Accepted answer

try this snippet:

var sortedvalues = values
    .orderbydescending(x => x.length)
    .thenbydescending(x => convert.toint32(x));

if you really need use it as a list, then add tolist() at the end.


values.orderbydescending(x => x.length).thenbydescending(x => int.parse(x));


most of the answers here are written using lambda syntax, if you want query syntax try this. result should be the same.

var sortedvalues = from x in values
                   orderby x.length descending, x descending
                   select x;


i'm going to assume you actually care about the value of each integer. if so:

var sortedvalues = values.orderbydescending(x => x.length)
                         .thenbydescending(x => int.parse(x));

this will yield a deferred iorderedenumerable<string>. the int.parse is only for the purpose of secondary ordering. if you need to materialize it, toarray or tolist will need to be called.

Related Query