The System.Collections.Hashtable is a collection class in C# that stores key-value pairs. The Add method is used to add a key-value pair to the Hashtable.
Example 1:
Hashtable ht = new Hashtable();
ht.Add("Name", "John");
This code creates a new Hashtable object and adds the key-value pair "Name" and "John" to it.
Example 2:
Hashtable ht = new Hashtable();
ht.Add(1, "One");
ht.Add(2, "Two");
ht.Add(3, "Three");
This code creates a new Hashtable object and adds three key-value pairs to it. The keys are integers and the values are strings.
Example 3:
Hashtable ht = new Hashtable();
ht.Add("Colors", new string[] { "Red", "Green", "Blue" });
This code creates a new Hashtable object and adds a key-value pair to it. The key is "Colors" and the value is an array of strings.
Package library: This code uses 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.