Archive for C#
Sorting with a second sort parameter
Its easier maybe to explain this with an example. Say I have list of Member objects with first name, last name and postcode and I am sorting on last name but would like to sort on first name if there two people with the same last name.
So assuming class Member, I would go like this:
List member = new List();
member.Sort(
delegate(Member member1, Member member2)
{
if (member1.LastName == member2.LastName)
return member1.FirstName.CompareTo(member2.FirstName);
else
return member1.LastName.CompareTo(member2.LastName);
});