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.


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.


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;

Related Articles