My name is Edward Tanguay. I'm an American software and web developer living and working in Berlin, Germany.
C# CODE EXAMPLE created on Tuesday, March 16, 2010 permalink
How to use OrderedDictionary to lookup items by string key or integer index
I had created a Dictionary with which I could lookup items by their string key but then I also needed to lookup the items by their integer index as well. This unfornately doesn't work with Dictionary since it is not an ordered list, but the non-generic OrderedDictionary worked nicely in my case, I just had to do the appropriate casting. You might also check at the above link for more ideas, e.g. inherit from KeyedCollection<TKey, TItem>.
using System;
using System.Collections.Specialized;

namespace TestOrderedDictionary882234
{
    class Program
    {
        static void Main(string[] args)
        {
            OrderedDictionary events = new OrderedDictionary();

            events.Add("first", "this is the first one");
            events.Add("second", "this is the second one");
            events.Add("third", "this is the third one");

            string description1 = events["first"].ToString();
            Console.WriteLine(description1);

            string description2 = events[1].ToString();
            Console.WriteLine(description2);

            Console.ReadLine();
        }
    }
}
need markup?