Generic Lambda Expression to sort collections of different types
Suppose you have many collections with different types that you want to sort, of course you can do it by OrderBy or OrderByDescending extension methods but you have to specify the order criteria every time you call these methods. If the order criteria is determined in runtime, then you have to build a separate function to each order criteria of each type. To clear what I want to tell you suppose you have two classes, Employee and Department . public class Employee { public String Name { get; set; } public Int32 Age { get; set; } public DateTime HiringDate { get; set; } } public class Department { public String DepartmentName { get; set; } public String Code { get; set; } } And you want to order the employee collection by one of its properties (Name,Age,or HiringDate) and order department collection by one of its properties. OrderBy and OrderByDescending methods need Func<TSource,TKey> as selector to compare the collection items and order them....