Equivalent of Python Dictionary

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • bg_ie@yahoo.com

    #1

    Equivalent of Python Dictionary

    Hi,

    I have my own class and I'd like to save objects of this class in a
    dictionary. In python this works something along the lines of:

    a = MyObject();
    b = MyObject();
    c = MyObject();

    myObjectDict = {}
    myObjectDict['a'] = a
    myObjectDict['b'] = b
    myObjectDict['c'] = c

    How do I do this in C#?

    Thanks,

    Barry

  • Marc Gravell

    #2
    Re: Equivalent of Python Dictionary

    (assumes 2.0, and note that I'm interpreting 'a' as a string not a
    char - hope this is correct ;-p)

    using System.Collecti ons.Generic;
    ....
    MyObject a = new MyObject(), b = new MyObject(), c = new MyObject();
    Dictionary<stri ng, MyObjectdict = new Dictionary<stri ng,
    MyObject>();
    dict["a"] = a;
    dict["b"] = b;
    dict["c"] = c;

    Marc


    Comment

    Working...