score:14

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.

score:4

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.

score:2

values.OrderByDescending(x => x.Length).ThenByDescending(x => int.Parse(x));

score:3

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;

Related Articles