First ignore my message in the other thread for your other message.
This thread clears things up.
What you would have to do it is use a Hashtable.
ListDictionary Objs = new ListDictionary();
for (int i=0; i<5; i++)
{
String tempStr = "obj" + i.ToString();
ASObject temp = new ASObject();
objs[tempStr] = temp;
}
Unfortunately, .Net doesn't offer a string-to-object hashtable class, just a
string-to-string, and an object-to-object. There is one string-to-object
abstract class (NameObjectCollectionBase), which includes direction to
derive a string-to-your own object class, which is probably what you want.
ALternately, if you know that names will follow the "objN" pattern, you
could just as well forgot of the "obj" part, and use an array:
ASObject[] objs = new ASObject[5];
for (int i=0; i<5; i++)
{
ASObject temp = new ASObject();
objs[i] = temp;
}
--
Truth,
James Curran
Home:
www.noveltheory.com Work:
www.njtheater.com
Blog:
www.honestillusion.com Day Job:
www.partsearch.com
(note new day job!)
"Peter" <pk******@hotmail.com> wrote in message
news:ea**************************@posting.google.c om...
Hi everybody,
I'm a new in C# and have a problem
I need to create dynamically the name of object
let's say "obj1", "obj2" etc. They're hashtables (Action Script
objects)
I'm doing like
String tempStr = "obj" + i.ToString();
then
ASObject tempStr = new ASObject();
this gives an problem, beacuse temStr is already defined as a string
and recasting in this context is not possible.
Java and VB can easy resolve it, not speaking about scripting
languages were exists special functions like Eval(), but C# has some
different way.
If somebody knows something about it?
Thanks a lot!