Skip to main content
๐Ÿ“œ WAYPOINT LESSON

Checkpoint โ€” Generics

โญ beginnerโณ 20 min read๐Ÿ“ Lesson 49 of 85

A typed in-memory repository: add, get, remove, and a constraint-driven query โ€” one class, every type.

Checkpoint: the generic repository

Task: implement nested generic class Solution.Repository<T> where T : IComparable<T>:

  1. void Add(T item) โ€” appends.
  2. int Count { get; }
  3. T Get(int index) โ€” ArgumentOutOfRangeException when out of range.
  4. bool Remove(T item) โ€” removes the first equal element; returns false when absent.
  5. T? Min() โ€” the smallest element; InvalidOperationException when empty.
  6. List<T> Sorted() โ€” a NEW list sorted ascending; the store's own order must not change.