System.Collections.Hashtable

Added in .NET 1.1
This is a collection of key/value pairs that are organised based on the hash code of the key.

System.Collections.Hashtable 

This collection stores information based on their unique key
Their key has an Int21 data type and is called a hash code.



Adding

System.Collections.Hashtable myHashtable; 
myHashtable = new System.Collections.Hashtable();

myHashtable.Add("GBP", 15);
myHashtable.Add("USD", 25);
myHashtable.Add("EUR", 35);

Retrieving Value

Value = HashTable[Key]; 
int myInteger = myHashtable["EUR"];



ContainsKey

System.Collections.Hashtable myHashtable; 
myHashtable = new System.Collections.Hashtable();

myHashtable.Add("Mon", new System.DateTime(2020,10,3));
myHashtable.Add("Tue", new System.DateTime(2021,10,3));
myHashtable.Add("Wed", new System.DateTime(2022,10,3));

if (myHashtable.ContainsKey("Tue")
{
   System.DateTime myDateTime;
   myDateTime = (System.DateTime)myHashtable["Tue"];
}

Clear

myHashtable.Clear(); 


Remove

myHashtable.Remove 

Generic Version

The generic version of this collection is System.Collections.Generic.Dictionary


© 2024 Better Solutions Limited. All Rights Reserved. © 2024 Better Solutions Limited TopPrevNext