๐ 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>:
void Add(T item)โ appends.int Count { get; }T Get(int index)โArgumentOutOfRangeExceptionwhen out of range.bool Remove(T item)โ removes the first equal element; returns false when absent.T? Min()โ the smallest element;InvalidOperationExceptionwhen empty.List<T> Sorted()โ a NEW list sorted ascending; the store's own order must not change.