简体   繁体   中英

Sort List<List<string>> by length in ascending order

我想知道如何排序List<List<string>>通过的长度List<string>升序排列?

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);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM