I want to sort a list of person say
List persons=new List();
persons.Add(new Person(\"Jon\",\"Bernald\",45000.89));
persons.Add(new P
To get this to work in a lambda, the expression needs to form a Comparison
public static void SortPeople(
this List lst, CompareOptions opt1,SortOrder ord)
{
lst.Sort((left, right) =>
{
int result;
// left and right are the two Person instances
if (opt1 == CompareOptions.Salary)
{
result = left.Salary.CompareTo(right.Salary);
}
else
{
string compStr1, compStr2;
if (opt1 == CompareOptions.FirstName)
{
compStr1 = left.FirstName;
compStr2 = right.FirstName;
}
else
{
compStr1 = left.LastName;
compStr2 = right.LastName;
}
result = compStr1.CompareTo(compStr2);
}
if (ord == SortOrder.Descending)
result *= -1;
return result;
});
}