The System.Collections Hashtable.Add method is a method used to add a new key-value pair to a Hashtable object. The method takes two parameters - a key and a value, and adds the pair to the Hashtable.
Example 1:
Hashtable ht = new Hashtable(); ht.Add("key1", "value1"); ht.Add("key2", "value2");
In this example, we create a new Hashtable object and add two key-value pairs to it using the Add method.
Example 2:
Hashtable ht = new Hashtable(); foreach(var item in myList) { ht.Add(item.Key, item.Value); }
In this example, we iterate through a list of key-value pairs and add them to a Hashtable using the Add method.
Example 3:
Hashtable ht = new Hashtable(); ht.Add("key1", new List{1,2,3}); ht.Add("key2", new List{4,5,6});
In this example, we add two key-value pairs to a Hashtable, with the value being a list of integers.
The System.Collections Hashtable.Add method is part of the System.Collections namespace, which is part of the .NET Framework Class Library.
C# (CSharp) System.Collections Hashtable.Add - 60 examples found. These are the top rated real world C# (CSharp) examples of System.Collections.Hashtable.Add extracted from open source projects. You can rate examples to help us improve the quality of examples.