Tutorialspoint

C# Clear a Hashtable

using System;
using System.Collections;

public class Demo {
   public static void Main() {
      Hashtable h = new Hashtable();
      h.Add(1, "Amit");
      h.Add(2, "Sachin");
      h.Add(3, "Rahul");
      Console.WriteLine("Keys and Values list:");
      foreach (var key in h.Keys ) {
         Console.WriteLine("Key = {0}, Value = {1}",key , h[key]);
      }
      // clear all key value pairs
      Console.WriteLine("The Hashtable key and Value Pairs are empty now...");
      h.Clear();
      foreach (var key in h.Keys ) {
         Console.WriteLine("Key = {0}, Value = {1}",key , h[key]);
      }
   }
}

Advertisements
Loading...