By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
431,731 Members | 1,104 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 431,731 IT Pros & Developers. It's quick & easy.

creating instances

P: n/a
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
Nov 22 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
=?Utf-8?B?cmVpa3M=?= <an*******@discussions.microsoft.com> wrote:
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.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 22 '05 #2

P: n/a
=?Utf-8?B?cmVpa3M=?= <an*******@discussions.microsoft.com> wrote:
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.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 22 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.