ListDictionary.Add(Object, Object) method is used to add an entry with the specified key and value into the ListDictionary.
public void Add (object key, object value);
key : The key of the entry to add.
value : The value of the entry to add. The value can be null.
- ArgumentNullException : If the key is null.
- ArgumentException : It is an entry with the same key already exists in the ListDictionary.
Below given are some examples to understand the implementation in a better way:
Total number of elements in myDict are : 6 Australia Canberra Belgium Brussels Netherlands Amsterdam China Beijing Russia Moscow India New Delhi
System.ArgumentNullException: Key cannot be null.
Parameter name: key
- An object that has no correlation between its state and its hash code value should typically not be used as the key. For example, String objects are better than StringBuilder objects for use as keys.
- This method is an O(n) operation, where n is Count.
- C# | Get or set the value associated with specified key in ListDictionary
- C# | Remove the entry with specified key from ListDictionary
- C# | Get the number of key/value pairs contained in ListDictionary
- C# | Copy ListDictionary to Array instance at the specified index
- C# | Check if ListDictionary contains a specific key
- C# | Adding the specified key and value into HybridDictionary
- C# | Insert into OrderedDictionary with key and value at specified index
- C# | Add key and value into StringDictionary
- C# | Add key and value into OrderedDictionary collection
- C# | Insert a new entry in OrderedDictionary with specified key and value
- C# | Get or Set the value associated with specified key in Hashtable
- C# | Get or set the value associated with the specified key in StringDictionary
- C# | Gets or sets the value in HybridDictionary with specified key
- C# | Get or set the value associated with specified key in SortedList
- C# | Gets or sets the value at the specified key in StringDictionary
- C# | Check if two ListDictionary objects are equal
- C# | ListDictionary Class
- C# | Remove all entries from the ListDictionary
- C# | Get an ICollection containing the values in ListDictionary
- C# | Get an ICollection containing the keys in ListDictionary
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.