Re: How to CAST string into object (hashtable)

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance

From: Jon Skeet [C# MVP] (skeet_at_pobox.com)
Date: 10/18/04


Date: Mon, 18 Oct 2004 02:58:07 +0100

Peter <pkorikov@hotmail.com> wrote:
> 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.

-- 
Jon Skeet - <skeet@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too


Relevant Pages

  • Re: CLOS and C++
    ... Peter, every counterexample you've come up with falls under this. ... OOP ... of sharing by Java users versus their peers is impressive, ... I think he spent too much time using an OOP language for ...
    (comp.lang.lisp)
  • Re: Project still using VB6
    ... Peter said that it was a great idea to move to VB.NET. ... I was in Java for a while but Sun just didn't cut it. ... C# is a joke... ... IMO almost any other choice would be a better one. ...
    (microsoft.public.vb.enterprise)
  • Re: php and perl
    ... peter wrote: ... I liked "C" but Java seems like the way to go for compiled langs, now days so I will learn that. ... I was wondering what you guys thinks of the pros/cons of perl and php. ...
    (comp.lang.php)
  • Re: Peter van der Linden
    ... I got "Just Java" back when it was 1.1. ... literally about a dozen problems I encountered coming from the C world ... (I'm an old-timer). ... thrilled to have Peter reply personally. ...
    (comp.lang.java.programmer)
  • Re: Download exe file geht nicht
    ... > Peter Ihm schrieb am 22.02.04: ... > Java und Java Script funktionieren? ... holen will, kommt erst die MS Seite, clicke ich dort rechts auf das Download ...
    (microsoft.public.de.german.inetexplorer.ie6)