The “Dictionary” class is a generic class; so you need to specify data type of the key and data type of the value while creating object. Reference :- System.Collections.Generic.Dictionary You can set / get the value based on the key and can’t be set null or duplicate.
Dictionary<TKey, TValue> dictVariable = new Dictionary<TKey, TValue>( );
Features of ‘Dictionary’ class It is dynamically sized. You can add, remove elements (key/value pairs) at any time. Key can’t be null or duplicate; but value can be null or duplicate. It is not index-based. You need to access elements by using key. It is not sorted by default. The elements are stored in the same order, how they are initialized.
Properties of ‘Dictionary’ class Count : Returns count of elements. [TKey] : Returns value based on specified key. Keys : Returns a collection of key (without values). Values : Returns a collection of values (without keys).
Methods of ‘Dictionary’ class void Add(TKey, TValue) : Adds an element (key/value pair). bool Remove(TKey) : Removes an element based on specified key. bool ContainsKey(TKey) : Determines whether the specified key exists. bool ContainsValue(TValue) : Determines whether the specified value exists. void Clear() : Removes all elements.