How to CAST string into object (hashtable)

  • Thread starter Thread starter Peter
  • Start date Start date
P

Peter

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!
 
Peter said:
I'm a new in C# and have a problem

I need to create dynamically the name of object

Objects don't have names. Variables have names, but objects don't
(generally).
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.

I presume by "Java" here you actually mean Javascript.
If somebody knows something about it?

Either use an array of objects, or use a hashtable mapping from name to
object.
 
Your description is quite vague on what you actually want to do.

For example, to solve the only problem you actually mention in your
message, all you need do is simply change

String tempStr = "obj" + i.ToString();
ASObject tempStr = new ASObject();

to

String tempStr = "obj" + i.ToString();
ASObject tempASO = new ASObject();

so, clearly that's not the real problem. Tell us a bit more clearly what
you want to use this for.

--
Truth,
James Curran
Home: www.noveltheory.com Work: www.njtheater.com
Blog: www.honestillusion.com Day Job: www.partsearch.com
(note new day job!)
 
Back
Top