SoFunction
Updated on 2025-03-08

Introduction and simple usage of hashtable in C#


using System;

using ; //When using Hashtable, this namespace must be introduced

class hashtable

{

public static void Main()

{

Hashtable ht=new Hashtable(); //Create a Hashtable instance

("E","e");//Add key/value pair

("A","a");

("C","c");

("B","b");

string s=(string)ht["A"];

if(("E")) //Judge whether the hash table contains a specific key, its return value is true or false

("the E key:exist");

("C");//Remove a key/value key-value pair

(ht["A"]);//Output a here
 }


//DictionaryEntry Object is required to traverse the hash table, the code is as follows:

for(DictionaryEntry de in ht) //ht is a Hashtable instance
 {
();// Corresponding to key/value key value pair
();//corresponding to key/value key-value pair value
 }
}