3

Currently in my query I am saying orderby t.Description and I get:

1st street
2 burritos
Allergy
Ameripath
Application
APK THD

How can I change the sort to get this:

1st street
2 burritos
APK THD
Allergy
Ameripath
Application

So now it is still by description but the ones with capital letters come first

1 Answers1

8

You have to pass a ordinal comparer to OrderBy method:

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);
}
brz
  • 5,926
  • 1
  • 18
  • 18
  • Thanks that would do it, except one issue: Before I return my query result, I am adding a one off item called "Show All" to the top of the list, but I don't want this one to get sorted, I want this one to still stay on top, How can I do that? Currently it sorts it like the rest of them. – ConfusedSleepyDeveloper Sep 16 '14 at 16:58
  • 2
    You have to add it after sorting the list. You can use list.Insert(0, "ShowAll"). – brz Sep 16 '14 at 19:09