How do I get the list of keys in a Dictionary

126

How do I get the list of keys in a Dictionary? -

List<string> keyList = new List<string>(this.yourDictionary.Keys);

How do I get the list of keys in a Dictionary? -

Dictionary<string, int> data = new Dictionary<string, int>();
data.Add("abc", 123);
data.Add("def", 456);
foreach (string key in data.Keys) // look carefully Keys is used with "s" in it
{
	Console.WriteLine(key);
}

Comments

Submit
0 Comments