StringDictionary.Add(String, String) method is used to add an entry with the specified key and value into the StringDictionary.
public virtual void Add (string key, string value);
- key: It is the key of the entry which is to be added.
- value: It is the value of the entry which is to be added. The value can be null.
- ArgumentNullException : If the key is null.
- ArgumentException : It is an entry with the same key already exists in the StringDictionary.
- NotSupportedException : If the StringDictionary is read-only.
Below programs illustrate the use of StringDictionary.Add(String, String) method:
d Dog b Banana c Cat e Elephant a Apple
System.ArgumentException: Item has already been added. Key in dictionary: ‘c’ Key being added: ‘c’
- The key is handled in a case-insensitive manner i.e, it is translated to lowercase before it is added to the string dictionary.
- This method is an O(1) operation.
- C# | Get the number of key/value pairs in the StringDictionary
- C# | Get or set the value associated with the specified key in StringDictionary
- C# | Gets or sets the value at the specified key in StringDictionary
- C# | Check if the StringDictionary contains a specific key
- C# | Remove entry with specified key from the StringDictionary
- C# | Add the specified key and value into the ListDictionary
- C# | Add key and value into OrderedDictionary collection
- C# | Check if the StringDictionary contains a specific value
- C# | Adding the specified key and value into HybridDictionary
- C# | Insert into OrderedDictionary with key and value at specified index
- C# | How to add key/value pairs in SortedList
- C# | Removing all entries from the StringDictionary
- C# | Copy StringDictionary to Array at the specified index
- C# | Check if StringDictionary is synchronized (thread safe)
- C# | Get an enumerator that iterates through the stringDictionary
- C# | Get a collection of keys in the StringDictionary
- C# | Get a collection of values in the StringDictionary
- C# | StringDictionary Class
- C# | Check if two StringDictionary objects are equal or not
- How to get Synchronize access to the StringDictionary in C#
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.