What can be done better in this code?  I am sure it's not missing much.You can copy and paste the whole thing in LinqPad; it's all there.public interface IRep<T>{    List<T> GetAll();}public interface IEntity{    int Id{get;set;}}public class Customer: IEntity{    public int Id { get; set; }    public string Name { get; set; }    public int Age { get; set; }}public class Product: IEntity{    public int Id { get; set; }    public string Code { get; set; }    public decimal Price {get;set;}}public class RepProduct: IRep<Product>{    public List<Product> GetAll()    {        List<Product> list = new List<Product>();        list.Add(new Product() {Id=1, Code = burger, Price = 2.99M});        list.Add(new Product() {Id=1, Code = fries, Price = 1.99M});        list.Add(new Product() {Id=1, Code = pepsi, Price = 1.99M});        return list;    }}public class RepCustomer: IRep<Customer>{    public List<Customer> GetAll()    {        List<Customer> list = new List<Customer>();        list.Add(new Customer() {Id=1,Name=Fred, Age=44   });        list.Add(new Customer() {Id=2,Name=Victoria, Age=13   });        list.Add(new Customer() {Id=3,Name=Kiefer, Age=10 });        return list;}}void Main(){    IRep<IEntity> rep = null;}
Proper implementation of generic repository
c#;interface
To get it to work, use IEnumerable<T> instead of List<T> as it's covariant:public interface IRep<out T>{    IEnumerable<T> GetAll();}public interface IEntity{    int Id { get; set; }}public class Customer: IEntity{    public int Id { get; set; }    public string Name { get; set; }    public int Age { get; set; }}public class Product: IEntity{    public int Id { get; set; }    public string Code { get; set; }    public decimal Price {get;set;}}public class RepProduct: IRep<Product>{    public IEnumerable<Product> GetAll()    {        List<Product> list = new List<Product>();        list.Add(new Product() {Id=1, Code = burger, Price = 2.99M});        list.Add(new Product() {Id=1, Code = fries, Price = 1.99M});        list.Add(new Product() {Id=1, Code = pepsi, Price = 1.99M});        return list;    }}public class RepCustomer: IRep<Customer>{    public IEnumerable<Customer> GetAll()    {        List<Customer> list = new List<Customer>();        list.Add(new Customer() {Id=1,Name=Fred, Age=44   });        list.Add(new Customer() {Id=2,Name=Victoria, Age=13   });        list.Add(new Customer() {Id=3,Name=Kiefer, Age=10 });        return list;    }}void Main(){    IRep<IEntity> rep = null;    rep = new RepCustomer();    Console.WriteLine(rep.GetAll());    rep = new RepProduct();    Console.WriteLine(rep.GetAll());}