473,387 Members | 1,582 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

creating instances

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
2 1337
=?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
=?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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: PerfectDayToChaseTornados | last post by:
Hi All, I was wondering what peoples opinions, or experience were with creating instances by reflection. How expensive is the following code? It is from a factory class, I was wondering whether to...
4
by: Altramagnus | last post by:
I have 30 - 40 type of different window. For each type I need about 20 instances of the window. When I try to create them, I get "Error creating window handle" My guess is there is a maximum...
7
by: nog | last post by:
What's the best approach to creating many objects of a class? I have in mind using something analogous to a table to hold the data - which is in a form similar to (char name, char address, date...
12
by: Mats Lycken | last post by:
Hi, I'm creating a CMS that I would like to be plug-in based with different plugins handling different kinds of content. What I really want is to be able to load/unload plugins on the fly without...
5
by: Devan L | last post by:
Is there any safe way to create an instance of an untrusted class without consulting the class in any way? With old-style classes, I can recreate an instance from another one without worrying about...
26
by: nyathancha | last post by:
Hi, How Do I create an instance of a derived class from an instance of a base class, essentially wrapping up an existing base class with some additional functionality. The reason I need this is...
2
by: ChrisO | last post by:
I've been pretty infatuated with JSON for some time now since "discovering" it a while back. (It's been there all along in JavaScript, but it was just never "noticed" or used by most until...
3
by: tedmoseby | last post by:
I am creating a website, using flash instances which will be dynamicly based on xml information (pulled from, the users, sql db; thru php). I am running into a problem, mapping this out on...
3
by: Peter Morris | last post by:
Hi all Let's say I am creating a model to represent classes and properties. In addition to this I need instances of classes and values for those properties. KEY: (AssociationEndName)
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.