![]() We then add elements to the hash table using the Add method.First, we declare the hashtable variable using the Hashtable data type by using keyword “New.” The name of the variable defines is ‘ht’.In the below program, we will write the code to see how we can use the above-mentioned methods.įor now in our example, we will just look at how we can create a hashtable, add elements to the hashtable and display them accordingly. The code will be written to our Program.cs file. All of the below-mentioned code will be written to our Console application. Now, let’s see this working at a code level. Remember that each element of the hash table comprises of 2 values, one is the key, and the other is the value. The general syntax of the statement is given below HashTable.add("key","value") Example 1: The Add method is used to add an element on to the queue. Hashtable ht = new Hashtable() Adding elements to the Hashtable The object is then assigned to the variable ht. The “new” keyword is used to create an object of a Hashtable. A Hashtable is created with the help of the Hashtable Datatype. The declaration of a Hashtable is shown below. Let’s look at the operations available for the Hashtable collection in more detail. The values of each key value pair are “.Net”, “C#” and “ASP.Net” respectively. The keys of each element are 001, 002 and 003 respectively. These 2 values form an element of the hash table.īelow are some example of how values of a hash table might look like. So instead of storing just one value like the stack, array list and queue, the hash table stores 2 values. A hash table is a special collection that is used to store key-value items. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. Archives
December 2022
Categories |