How to get all keys of a dictionary with C#
The Keys property gets a collection containing the keys in the Dictionary. It returns an object of KeyCollection type.
The following code snippet reads all keys in a Dictionary.
- Dictionary<string, Int16> AuthorList = new Dictionary<string, Int16>();
- AuthorList.Add("Mahesh Chand", 35);
- AuthorList.Add("Mike Gold", 25);
- AuthorList.Add("Praveen Kumar", 29);
- AuthorList.Add("Raj Beniwal", 21);
- AuthorList.Add("Dinesh Beniwal", 84);
- // Get and display keys
- Dictionary<string, Int16>.KeyCollection keys = AuthorList.Keys;
- foreach (string key in keys)
- {
- Console.WriteLine("Key: {0}", key);
- }
Output
Next>>Using Dictionary in C#

정진영Posted Jun 12, 2025, 7:48 AM
hi, i'm beginner developer. i have question. what diffrence is the make a new List?