creating instances of objects

G

Guest

Is it possible to create instances at runtime. i.e the type of the variable will be known at runtime.
for example,see this simple sample code

class A
{
// events and methods
}
class B
{
// events and fucntions
}

void main()
{
string s
int i=9
if(i==9)
s="A"
else
s="B"

c1 = new s // At runtime , the time of the variable is made known

}

How can I acheive this?

plzz help me out
 
P

Paulo Lisboa [MSFT]

Notice that there are different classes offering methods to instantiate
objects for types you just know at runtime (e.g. Assembly, Type, or
ConstructorInfo). However, by reading the documentation you will notice that
some of these classes are just internally calling Activator.

--
Thanks.
Paulo

DISCLAIMER: This posting is provided "AS IS" with no warranties, and confers
no rights. Use of any included code samples are subject to the terms
specified at http://www.microsoft.com/info/cpyright.htm"
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top