C# list sort by two columns

前端 未结 7 1115
慢半拍i
慢半拍i 2020-12-15 21:08

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

7条回答
  •  无人及你
    2020-12-15 21:58

    result.Sort((x,y) => x.CheckedIn==y.CheckedIn ? 
      string.Compare(x.LastName, y.LastName) : 
      (x.CheckedIn ? -1 : 1) );
    

提交回复
热议问题