Variables
Dictionaries in C#
A dictionary is used to store key-value pairs.
Syntax
///creating a dictionary
Dictionary<Key_DataType, Value_DataType> dictionaryName = new Dictionary<Key_DataType, Value_DataType>();
//adding values to the hash map
dictionaryName.Add(key, value);
//getting value from key
keyValue = dictionary["key"]
Notes
It is equivalent to a HashMap in Java, or an object in JavaScript.
The data types are generic types.
The ContainsKey method verifies the presence of the key in the dictionary.
Example
public Dictionary<string, int> grades = new Dictionary<string, int>();
grades.put("Paul", 70);
grades.put("Adam", 85);
Console.WriteLine(grades["Paul"]); //will get the value associated with Paul, 70