← C# Programming learning path
C# Programming · Module 5 of 10

Collections and generics

Store data in List, Dictionary and use generics.

📖 Key ideas

  1. List<T> is a resizable array: var nums = new List<int>();
  2. Dictionary<TKey, TValue> maps keys to values.
  3. HashSet<T> holds unique items; Queue and Stack exist too.
  4. Generics give type-safe reusable code.
  5. Collection expressions: int[] a = [1, 2, 3];
💡 Real-life example: Generics are labelled containers: List<Book> only accepts books.
List<T>Generic resizable list
DictionaryKey-value collection
HashSetUnique items set
GenericType parameter <T>