PC Review


Reply
Thread Tools Rate Thread

creating instances of objects

 
 
=?Utf-8?B?cmVpa3M=?=
Guest
Posts: n/a
 
      19th Jan 2004
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


 
Reply With Quote
 
 
 
 
Jan Tielens
Guest
Posts: n/a
 
      19th Jan 2004
This is possible using the Activator.CreateInstance method:
http://tinyurl.com/29rtl

--
Greetz

Jan Tielens
________________________________
Read my weblog: http://weblogs.asp.net/jan


"reiks" <(E-Mail Removed)> wrote in message
news:743E1001-9BCE-4B3D-8367-(E-Mail Removed)...
> 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
>
>



 
Reply With Quote
 
Paulo Lisboa [MSFT]
Guest
Posts: n/a
 
      20th Jan 2004

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"


"Jan Tielens" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> This is possible using the Activator.CreateInstance method:
> http://tinyurl.com/29rtl
>
> --
> Greetz
>
> Jan Tielens
> ________________________________
> Read my weblog: http://weblogs.asp.net/jan
>
>
> "reiks" <(E-Mail Removed)> wrote in message
> news:743E1001-9BCE-4B3D-8367-(E-Mail Removed)...
> > 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
> >
> >

>
>



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Creating instances of a control =?Utf-8?B?Um9iZQ==?= Microsoft Dot NET Framework Forms 1 1st Aug 2006 04:07 AM
Watch instances of objects Benjamin Lukner Microsoft Dot NET Compact Framework 4 18th Feb 2005 11:30 AM
creating instances =?Utf-8?B?cmVpa3M=?= Microsoft Dot NET Framework 2 19th Feb 2004 02:01 PM
creating instances =?Utf-8?B?cmVpa3M=?= Microsoft Dot NET 1 19th Jan 2004 09:56 AM
object instances in Custom Objects Eric Cathell Microsoft VB .NET 2 18th Oct 2003 06:42 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 08:55 PM.