Dictionary
Learn to store key-value pairs.
Overview
Dictionaries are key-value stores. These are mappings between keys and associated values. We can imagine a dictionary as a book where we have words and associated translations. Words are keys and translations are values:
An example of a dictionary
Keys in .NET dictionaries must be unique. It’s impossible to have two identical keys. Values aren’t unique, though.
Syntax
Dictionaries in .NET are created by instantiating the Dictionary<K, V>
class. We can use any type as a key and any type as a value: