Search code examples
c#.netwindows-phone-7collections

Windows Phone 7 - OrderedDictionary / alternatives


I'm completely new to C#, so I'm about to make a horrible attempt at my own version of an OrderedDictionary unless someone can suggest an alternative.

I need to be able to access my elements by array index, retaining the order they were added, and I also will be frequently updating individual elements using their key.

  1. Is there a collection that allows this on the phone?

  2. If I keep a List and Dictionary will they both be pointing to the same item or is there some kind of pointer thing I have to do?:

    Item i = new Item();
    list.Add(i);
    dict.Add("key", i);
    

Solution

  • Using a List and a Dictionary is probably a good option actually. The "pointer thing" that you're talking about happens by default for Objects in .NET (any class and/or structure). All objects in .NET are passed around by reference.

    So, if you use:

    Item i = new Item();
    list.Add(i);
    dict.Add("key",i);
    Console.WriteLine(list.Last() == dict["key"]);
    

    Your output will be "true".

    Best of luck!