I have a C# custom object list that I need to sort by two different variables one is a boolean and the other is a string. I can sort by either of the criteria, but I'm having trouble figuring out how to combine them. The sort should be all of the boolean values first (CheckedIn) and then the last name for each of the values. Right now I use
result.Sort((x, y) => string.Compare(x.CheckedIn.ToString(), y.CheckedIn.ToString()));
result.Sort((x, y) => string.Compare(x.LastName, y.LastName));
But how can I combine then so that my results are like
CheckedIn-Name
No - Aames
No - Smith
Yes - Barnes
Yes - Peters
use linq.
if you have list L of objects of class
public class temp
{
public bool x;
public string y;
}
then use:
L.orderby(a=>a.x).thenby(a=>a.y);
you can chain it as far as you like.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With