Junior
From PDF
Collections
C# Collections
What is a Dictionary<TKey, TValue> in C#?
A Dictionary<TKey, TValue> is a generic collection in C# that stores data as
key-value pairs. It provides fast lookup, addition, and removal of values based on their
keys.
- Keys must be unique
- Keys must be non-null (for reference types)
- Values can be null if the type allows it
Example:
Dictionary<string, int> ages = new Dictionary<string, int>();
ges.Add("Alice", 30);
ges.Add("Bob", 25);
Use case: Storing user profiles by ID, or mapping product names to prices.
Share this Q&A
Share preview image: https://www.toolliyo.com/images/toolliyo-logo.png