Dictionary
Learn to store key-value pairs.
We'll cover the following...
We’ve explored collections like lists, stacks, and queues. While these are excellent for managing sequences of data, they rely on sequential ordering or numeric indices to retrieve items. But what if we need to look up a user’s profile using their email address, or find a product’s price using its barcode? Searching through a massive list item by item would be incredibly slow.
To solve this, .NET provides the dictionary. This collection is optimized for fast lookups using unique keys instead of numeric indices. Because dictionaries use hashing internally, retrieving a value by its key operates in
Dictionaries are key-value stores. These are mappings between keys and associated values. Think of a dictionary like a physical translation book where the words serve as unique keys and the translations serve as the values: