The Values property gets a collection containing the values in the Dictionary. It returns an object of ValueCollection 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 values
- Dictionary<string, Int16>.ValueCollection values = AuthorList.Values;
- foreach (Int16 val in values)
- {
- Console.WriteLine("Value: {0}", val);
- }
Output
Next>> Using Dictionary in C#

Susan LlewellynPosted Sep 14, 2021, 5:16 PM
This is useful, but what I really want to know is how to get all the values for a particular key, when the KeyValuePair is KVP<Int64, List<Int64>>.