Skip to main content

Practice · 2 of 3

The Typed Repository

CHALLENGE
Difficulty: intermediate+25 XP

Implement Repository<T> where T : IHasId: Add stores by Id (re-adding REPLACES), Get returns default when absent, Count and All round out the surface. ``csharp public interface IHasId { int Id { get; } } public class Repository<T> where T : IHasId { public void Add(T entity); public T? Get(int id); public int Count { get; } public IReadOnlyCollection<T> All(); } ``

Back to lesson: Practice: Generic Design Practice