Hash Table C#
Hash Table is a Table, which works on Hash values. Not only in C# but almost all of the programming languages there are Hash Tables. A key in a dictionary data structure or any index in an array has a hash value by which it is accessed. So, Hash Table preserves the collection of Hash values. Hash Table itself is also a data structure.
- Create a new project. Add a new class.
- Include System.Collection.Generics by
Now after that type the following code(explained in comments):
public void testHashTable()
Hashtable hashTable= new Hashtable();
// (hashTable) is basically the data structure which we are using and(hashTable) //is an object of (Hashtable).
//Add is basically the built in function in c# which is associated with (Hashtable). //Anything typed in the brackets of Add() function will be added in (Hashtable). It //is adding the hash value of the key which is 1 to the hashTable
hashTable.Add(2, newEmployee("saeed", "345-4545343-34", 23, 6.0));
hashTable.Add(6, newDoctor("saad", "32343-343434-34", 42, 5.5,"Asst Prof"));
//call methods to remove, clear, count etc.
Now in main(), make the instance of your class and call the functions in the following way:
CollectionTest test=new CollectionTest();