首先按大写字母排序

时间:2014-09-16 15:32:07

标签: c# linq linq-to-entities

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

1st street
2 burritos
Allergy
Ameripath
Application
APK THD

如何更改排序以获取此信息:

1st street
2 burritos
APK THD
Allergy
Ameripath
Application

所以现在仍然是描述,但大写字母首先出现

1 个答案:

答案 0 :(得分:7)

您必须将有序比较器传递给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);
}