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

Athiwat Chunlakhan picture Athiwat Chunlakhan · Aug 14, 2009 · Viewed 297k times · Source

I only want the Keys and not the Values of a Dictionary.

I haven't been able to get any code to do this yet. Using another array proved to be too much work as I use remove also.

How do I get a List of the Keys in a Dictionary?

Answer

Camal picture Camal · Aug 14, 2009
List<string> keyList = new List<string>(this.yourDictionary.Keys);