C# sorting strings small and capital letters

前端 未结 2 1858
攒了一身酷
攒了一身酷 2021-01-19 19:07

Is there a standard functionality which will allow me to sort capital and small letters in the following way or I should implement a custom comparator:

stude         


        
2条回答
  •  无人及你
    2021-01-19 19:49

    Do you mean something on these lines

    List sort = new List() { "student", "Students", "students", 
                                             "Student" };
    List custsort=sort.OrderByDescending(st => st[0]).ThenBy(s => s.Length)
                                                             .ToList();
    

    The first one orders it by the first character and then by the length. It matches the output you suggested by then as per the pattern i mentioned above else you will do some custom comparer

提交回复
热议问题