先按大写字母排序

本文关键字:排序 大写字母 | 更新日期: 2023-09-27 18:22:08

当前在我的查询中,我说的是orderby t.Description,我得到的是:

1st street
2 burritos
Allergy
Ameripath
Application
APK THD

我如何更改排序以获得此:

1st street
2 burritos
APK THD
Allergy
Ameripath
Application

所以现在它仍然是按描述的,但大写字母在前的

先按大写字母排序

您必须将一个序数比较器传递给OrderBy方法:

static void Main(string[] args)
{
    var list = new[] {"1st street","2 burritos","Allergy","Ameripath","Application","APK THD"};
    list.OrderBy(x => x, StringComparer.Ordinal).ToList().ForEach(Console.WriteLine);
}