What is the Values property of Hashtable class in C#?


The Values property gets an ICollection containing the values in the Hashtable.

Declare Hashtable collection −

Hashtable ht = new Hashtable();

Now add values

ht.Add("One", "Henry");
ht.Add("Two", "Kevin");
ht.Add("Three", "David");

To display values from Hashtable, the following is the code −

Example

 Live Demo

using System;
using System.Collections;

namespace Demo {
   class Program {
      static void Main(string[] args) {
         Hashtable ht = new Hashtable();

         ht.Add("One", "Henry");
         ht.Add("Two", "Kevin");
         ht.Add("Three", "David");

         // Displaying values
         foreach (string value in ht.Values) {
            Console.WriteLine(value);
         }

         Console.ReadKey();
      }
   }
}

Output

David
Henry
Kevin

Updated on: 20-Jun-2020

60 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements