As a developer, we play more with IList<T>. With the help of Generics and using Enumerable.OfType<TResult> we can retrieve objects of type<T> from List<T> in more elegant way.
Example:
Lets assume we have a List<T> where T is of type Person. Student and Employee are two classes derived from Person.
List<Person> personlist = new List<Person>();
personlist.Add(new Student());
personlist.Add(new Person());
personlist.Add(new Student());
personlist.Add(new Person());
Now, to get Person of type Student, below is method using Generics and LINQ
public IList<T> GetList<T>() where T: Person
{
return personlist.OfType<T>().ToList();
}
now, to get List<Employee> from personlist query like below
List<Employee> employeelist = GetList<Employee>();