Search code examples
c#.netlinqsystem.data

Sorting OrderedEnumerableRowCollection .. strings like 00-000, 01-000 are not sorted as expected


i've got some records from a query like this

SortingCode (column) Row: 00-005 Row: 00-000

the folowing code, doesn't sort this ...

var items = 
    from c in table
    orderby c.SortingCode
    select c;

Solution

  • You will have to explain what result you are expecting, because the following code

    var items = new List<string>() { "00-005", "01-004", "00-003" };
    
    foreach (var item in items.OrderBy(i => i))
    {
        Console.WriteLine(item);
    }
    

    Do output

    00-003
    00-005
    01-004
    

    Which seem well sorted for me. What result are you expecting?