May I know how to sort List<List<string>>
by the length of List<string>
in ascending order?
var result = list.OrderBy(x => x.Length)
Have a look at the List<T>.Sort method:
listOfListOfStrings.Sort((a, b) => a.Length.CompareTo(b.Length));
Alternatively, you can create an IEnumerable<List<string>> from the List<List<string>> that returns the lists in sorted order when enumerated, but leaves the original list untouched:
IEnumerable<List<string>> result = listOfListOfStrings.OrderBy(x => x.Length);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With