Community discussion forum

Naming object instances with strings

Tags:
  • 3 months ago

    => Just for an straight easy way :

    string[] myStringArray = { "value1", "value2", "value3" };

    Dictionary<string, object> objects = new Dictionary<string, object>(); // pair of 'object name'(string) and 'object value'(object) (instead of 'object' type, you can use your type 'myObject')

     

    // optionally, you can create all of your objects in this way :

    foreach (string objectname in myStringArray)

                objects[objectname] = new myObject();

    // then you can use each of your objects like this : objects[myStringArray[1]]

     

Post a reply

Enter your message below

Sign in or Join us (it's free).