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

CsharpProgrammingServer Side Programming

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
raja
Published on 08-Aug-2018 10:45:34
Advertisements