Hashtable

The Hashtable stores values in Key-Value Pairs, with the help of key the value, is
retrieved here.

It has the following methods:

- Add() method to add the elements

- Remove() method to remove the elements

Example 4: Hashtable collection adding and removing the element.

 

using System;
namespace SampleProgram {
  class MySample {
    public static void Main(string[] args) {
      Hashtable hashList = new Hashtable();
      hashList.Add(10, 100);
      hashList.Add(20, true);
      hashList.Add(" greet ", " Hi ");
      hashList.Add(30, 23.5);
      Console.WriteLine($ " Read by key greet: {
        hashList[ " greet "]
      } ");
      Console.WriteLine();
      Console.WriteLine(" Read all values by key ");
      foreach(object m in hashList.Keys) {
        Console.Write($ " {
          hashList[m]
        }");
      }
    }
  }
}

 

The output will be:

Read by key greet: Hi
Read all values by key
True 100 23.5 Hi

 

 

Related Tutorials