C# list sort by two columns

前端 未结 7 1103
慢半拍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:50

    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.

提交回复
热议问题