How to get all values of a dictionary with C#

How to get all values of a dictionary with C#. The Values property gets a collection containing the values in the C# Dictionary. It returns an object of ValueCollection type.

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.  

  1. Dictionary<string, Int16> AuthorList = new Dictionary<string, Int16>();  
  2. AuthorList.Add("Mahesh Chand", 35);  
  3. AuthorList.Add("Mike Gold", 25);  
  4. AuthorList.Add("Praveen Kumar", 29);  
  5. AuthorList.Add("Raj Beniwal", 21);  
  6. AuthorList.Add("Dinesh Beniwal", 84);   
  7.   
  8. // Get and display values  
  9. Dictionary<string, Int16>.ValueCollection values = AuthorList.Values;  
  10. foreach (Int16 val in values)  
  11. {  
  12.     Console.WriteLine("Value: {0}", val);  
  13. }
Output