creating instances

  • Thread starter Thread starter Guest
  • Start date Start date
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?

plx help me out

thanks in advance
rreiks
 
=?Utf-8?B?cmVpa3M=?= said:
Is it possible to create instances at runtime. i.e the type of the
variable will be known at runtime.

Yes. See Activator.CreateInstance and Type.GetType.
 
Back
Top