Generic Collections in C#
From the C# Programming Language cheat sheet · Collections and Generics · verified Jul 2026
Generic Collections
List, Dictionary, and other generic collections
csharp
// List<T>
List<string> names = new List<string> { "Alice", "Bob" };
names.Add("Charlie");
// Dictionary<TKey, TValue>
Dictionary<string, int> ages = new Dictionary<string, int>();
ages["Alice"] = 30;
ages["Bob"] = 25;
// Array
int[] numbers = { 1, 2, 3, 4, 5 };
// HashSet<T>
HashSet<int> uniqueNumbers = new HashSet<int> { 1, 2, 3 };💡 Generic collections provide type safety and performance
⚡ Dictionary provides O(1) average lookup time
📌 HashSet automatically handles uniqueness of elements
🟢 Queue (FIFO) and Stack (LIFO) for specific ordering needs