public static OrderedDictionary Drinks = new OrderedDictionary();
Drinks["Water"] = 3;
Drinks["Coffee"] = 2
Drinks["Beer"] = 5;
How can I get Item name by position? I want when i specify position 1 to get "Water".
public static OrderedDictionary Drinks = new OrderedDictionary();
Drinks["Water"] = 3;
Drinks["Coffee"] = 2
Drinks["Beer"] = 5;
How can I get Item name by position? I want when i specify position 1 to get "Water".
Try this :
For value:
var result= (Drinks.Cast<DictionaryEntry>().ElementAt(2)).Value;
For Key
var result= (Drinks.Cast<DictionaryEntry>().ElementAt(2)).Key;
Try this,
var result = Drinks.Keys.OfType<string>().ElementAt(0);
This will return first key of OrderedDictionary. Here you are sure that your key type is string. but if you are not sure data type of key then use object
like,
var result = Drinks.Keys.OfType<object>().ElementAt(0);