473,385 Members | 2,004 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,385 software developers and data experts.

Dynamically creating a object

In unmanaged application
CREATE USING allows your application to choose the object
type dynamically. It is usually used to instantiate an
ancestor variable with an instance of one of its
descendants. The particular descendant is chosen at
execution time.
For example, if uo_a has two descendants: uo_a_desc1 and
uo_a_desc2, then the application can select the object to
be created based on current conditions:

uo_a uo_a_var

string ls_objectname

IF ... THEN
ls_objectname = "uo_a_desc1"
ELSE
ls_objectname = "uo_a_desc2"
END IF
uo_a_var = CREATE USING ls_objectname

How can we achieve this in managed code ie., in C#.


Thank you
Jul 21 '05 #1
2 1446
Vannela <an*******@discussions.microsoft.com> wrote:
In unmanaged application
CREATE USING allows your application to choose the object
type dynamically. It is usually used to instantiate an
ancestor variable with an instance of one of its
descendants. The particular descendant is chosen at
execution time.
For example, if uo_a has two descendants: uo_a_desc1 and
uo_a_desc2, then the application can select the object to
be created based on current conditions:

uo_a uo_a_var

string ls_objectname

IF ... THEN
ls_objectname = "uo_a_desc1"
ELSE
ls_objectname = "uo_a_desc2"
END IF
uo_a_var = CREATE USING ls_objectname

How can we achieve this in managed code ie., in C#.


I believe you're after Activator.CreateInstance.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Jul 21 '05 #2
Vannela <an*******@discussions.microsoft.com> wrote:
In unmanaged application
CREATE USING allows your application to choose the object
type dynamically. It is usually used to instantiate an
ancestor variable with an instance of one of its
descendants. The particular descendant is chosen at
execution time.
For example, if uo_a has two descendants: uo_a_desc1 and
uo_a_desc2, then the application can select the object to
be created based on current conditions:

uo_a uo_a_var

string ls_objectname

IF ... THEN
ls_objectname = "uo_a_desc1"
ELSE
ls_objectname = "uo_a_desc2"
END IF
uo_a_var = CREATE USING ls_objectname

How can we achieve this in managed code ie., in C#.


I believe you're after Activator.CreateInstance.

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

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Eric | last post by:
How can I dynamically assign an event to an element? I have tried : (myelement is a text input) document.getElementById('myelement').onKeyUp = "myfnc(param1,param2,param3)"; ...
8
by: Falc2199 | last post by:
Hi, Does anyone know how to make this work? var sectionId = 5; repeat_section_sectionId(); function repeat_section_5(){ alert("firing"); }
6
by: Simon Verona | last post by:
I would normally use code such as : Dim Customer as new Customer Dim t as new threading.thread(AddressOf Customer.DisplayCustomer) Customer.CustomerId=MyCustomerId t.start Which would create...
7
by: pmclinn | last post by:
I was wondering if it is possible to dynamically create a structure. Something like this: public sub main sql = "Select Col1, Col2 from Table a" dim al as new arraylist al =...
3
by: Daniel Friend | last post by:
I have an application and use custom user controls as plugins. Is there any way to communicate back and forth from control to app. NOTE: The control is not refrenced in the app, it will act as a...
5
by: SalamElias | last post by:
I am creating several chkBoxes dynamically and assigning an event handler in the Page_load as foillows ***************************** Dim chkCatOption As CheckBox = New CheckBox chkCatOption.Text...
6
by: Bjorn Sagbakken | last post by:
Hello In VS2005: I am adding buttons and textboxes dynamically into a table, that also dynamically expands. So far, so good, actually very nice. But I am having trouble starting the desired...
6
by: RSH | last post by:
Hi, i have a situation where I need to dynamically create objects in a loop. My question surrounds intantiation naming in such a scenerio. Below is a snippet that is basically hardcoding each...
10
by: Jess | last post by:
Hello, If I create a temporary object using a dynamically created object's pointer, then when the temporary object is destroyed, will the dynamically created object be destroyed too? My guess...
4
by: mohaaron | last post by:
I can think of a lot of reasons why this might need to be done but as far as I can tell it's not possible. I've been looking for a way to add HtmlTableRows to a table using a button click for a...
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
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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.