C# | Add key and value into StringDictionary
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.