get keys from dictionary
Published: 9. October 2011 | Updated: 27. October 2011License: Microsoft Public License (MS-PL)
Categories: Collections » Linq
Tags: Basics C# Collections
Import namespaces
using System.Collections.Generic; using System.Linq;
Code
var dictionary = new Dictionary<int, string>(); dictionary.Add(1, "a"); dictionary.Add(3, "c"); dictionary.Add(5, "e"); var keysArray = dictionary.Keys.ToArray(); foreach (int i in keysArray) { Console.WriteLine(i); }Console Output:
1
3
5
3
5
| Send us feedback about this snippet » |





