C# sorting strings small and capital letters

c#, case-sensitive, sorting, string

Solution

Do you mean something on these lines

List<string> sort = new List<string>() { "student", "Students", "students", 
                                         "Student" };
List<string> 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

Problem

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: ``` student students Student Students ``` For an instance: ``` using System; using System.Collections.Generic; namespace Dela.Mono.Examples { public class HelloWorld { public static void Main(string[] args) { List<string> list = new List<string>(); list.Add("student"); list.Add("students"); list.Add("Student"); list.Add("Students"); list.Sort(); for (int i=0; i < list.Count; i++) Console.WriteLine(list[i]); } } } ``` it sorts the string as: ``` student Student students Students ``` If I try to use `list.Sort(StringComparer.Ordinal)`, the sorting goes like: ``` Student Students student students ```

Original source