I will explain my issue with this example:
ICollection<Employee> listOfEmployee = new List<Employee>();
//listOfEmployee = Some code;
In C#, List<T>
inherits from IList<T>, ICollection<T>, IEnumerable<T>, IEnumerable, IList, ICollection, IReadOnlyList<T>, IReadOnlyCollection<T>
interfaces. So this means List<T>
have all methods that these intercafes have.
In this example above why do we sometimes use
ICollection<Employee> listOfEmployee = new List<Employee>();
or
IEnumerable<Employee> listOfEmployee = new List<Employee>();
etc... instead of
List<Employee> listOfEmployee = new List<Employee>();
this? Is there any performance benefits or something?