Ordered Dictionary

When we need to represent the data as key/ pair, the best option is Ordered Dictionary. We later access the data using key or index.
Namespace

We need to use two namespaces.
  1. using System.Collections.Specialized;
  2. using System.Collections;
We use System.Collections namespace if we need to retrieve the data using ICollection.
Code
  1. OrderedDictionary person = new OrderedDictionary();
  2. person.Add("Name","Salman");
  3. person.Add("Address","Pakistan");
Retrieve the data using LINQ Element Query Operator.
  1. for(int i=0; i<person.Count; i++)
  2. {
  3. var item = person.ElementAt(i);
  4. Console.WriteLine("Key: " + item.Key);
  5. Console.WriteLine("Value: " + item.Value);
  6. }
Retrieve the data usnig ICollection.
  1. ICollection keyCOllection = person.Keys;
  2. ICollection valueCollection = person.Values;
  3. String[] myKeys = new String[person.Count];
  4. String[] myValues = new String[person.Count];
  5. keyCOllection.CopyTo(myKeys, 0);
  6. valueCollection.CopyTo(myValues, 0);
  7. for(int i=0; i<person.Count; i++)
  8. {
  9. Console.WriteLine("Key: " + myKeys[i]);
  10. Console.WriteLine("Value: " + myValues[i]);
  11. }
I hope you understand.