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

Object name as variable

How can I declare a new object with a variable name ?
I'm trying to add many objects with s for each loop
for ....
Object varname = new Object() ......
Nov 15 '05 #1
5 5476
"Sorin Sandu" <ss****@bizland.ro> wrote in news:O3l8ipgmDHA.360
@TK2MSFTNGP12.phx.gbl:
How can I declare a new object with a variable name ?
I'm trying to add many objects with s for each loop
for ....
Object varname = new Object() ......


if i understand you correctly you want pass the name of the object type in
a string...

using System.Reflection;

Assembly.GetExecutingAssembly().CreateInstance(... ..)

or

Activator.CreateInstance(....)

--
best regards

Peter Koen
-----------------------------------
MCAD, CAI/R, CAI/S, CASE/RS, CAT/RS
http://www.kema.at
Nov 15 '05 #2
Sorin Sandu <ss****@bizland.ro> wrote:
How can I declare a new object with a variable name ?
You can't.
I'm trying to add many objects with s for each loop
for ....
Object varname = new Object() ......


That sounds like a perfect place to use an array, or an ArrayList.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 15 '05 #3
On Fri, 24 Oct 2003 11:37:13 +0300, Sorin Sandu <ss****@bizland.ro> wrote:
How can I declare a new object with a variable name ?
I'm trying to add many objects with s for each loop
for ....
Object varname = new Object() ......


You don't need a new name for each object. If you store the objects in an
array they will each get a "name" as ArrayList[x].

If you need to add your own name, one way could be to create a new struct
having a name and an object.

--
Using M2, Opera's revolutionary e-mail client: http://www.opera.com/m2/
Nov 15 '05 #4
That would be interesting code if u could :D
Imagine debugging that :D

"Morten Wennevik" <Mo************@hotmail.com> wrote in message
news:oprxjm59kphntkfz@localhost...
On Fri, 24 Oct 2003 11:37:13 +0300, Sorin Sandu <ss****@bizland.ro> wrote:
How can I declare a new object with a variable name ?
I'm trying to add many objects with s for each loop
for ....
Object varname = new Object() ......


You don't need a new name for each object. If you store the objects in an
array they will each get a "name" as ArrayList[x].

If you need to add your own name, one way could be to create a new struct
having a name and an object.

--
Using M2, Opera's revolutionary e-mail client: http://www.opera.com/m2/
Nov 15 '05 #5
My point is you only need a reference to the object, not the original name
of it.

--
Using M2, Opera's revolutionary e-mail client: http://www.opera.com/m2/
Nov 15 '05 #6

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

Similar topics

4
by: Lucas Sain | last post by:
Hi, I think thta for this I have to use reflection... but I'm not shure. How can I find/get an object at runtime by looking for its name that is stored in a variable. For example: I have a...
7
by: William Apple | last post by:
Despite the fact this deals with webservices I believe it is a VB question. I am working on a test application that passes data to a webservice. The webservices takes a variable type that is...
3
by: | last post by:
Hi all, I have a question on reflection Lets say I have a custom object called Address. Now, lets say I have a string variable that holds the name of a variable in the object such as...
26
by: yb | last post by:
Hi, Is there a standard for the global 'window' object in browsers? For example, it supports methods such as setInterval and clearInterval, and several others. I know that w3c standardized...
14
by: Philipp Reif | last post by:
Hi all, I've got a little hole in my head concerning references. Here's what I'm trying to do: I'm calling a function, passing the reference of a business object for editing. The function clones...
4
by: alex | last post by:
I am so confused with these three concept,who can explained it?thanks so much? e.g. var f= new Function("x", "y", "return x * y"); function f(x,y){ return x*y } var f=function(x,y){
6
by: Bugs | last post by:
Does anyone have any recommendations on the best way to create multiple instances of the same class when the final number of instances is unknown? For example, I have a class and based on some...
23
by: Hugh Oxford | last post by:
How do I get an object's name? EG. $obj_FOO = new Bar; echo $obj_FOO->getName(); 'obj_FOO'
275
by: Astley Le Jasper | last post by:
Sorry for the numpty question ... How do you find the reference name of an object? So if i have this bob = modulename.objectname() how do i find that the name is 'bob'
2
by: ismailc | last post by:
Hi, I don't know xml. The stylesheet identifies all the objects from DB & as it reads through the DB, it checks the next object "for-each", I need to check the third object as well & define within...
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: 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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.