(Assume there is a class called opportunity that has a property called Properties, which returns a value type based on a column name and that there exist methods to give what column the user clicked on and what order did he want)
List
int ascending = GetOrder(); // This method will return 1 if ascending and -1 if
// descending
string columnName = GetSortedColumn(); // Get the name of the column to be sorted
// One-liner sort
opportunities.Sort((a, b) => ascending * ((IComparable)a.Properties [columnName] ).CompareTo(b.Properties[columnName]));
Isnt this real simple? Now, the additional benefit that we get out of this is the ability to pass in local variables (ascending and columnName in this case) into the lambda expression and thereby the comparison, which would have never been possible if I used the "implementing IComparable or IComparer" route.
Happy Linqing!!