开发者

Convert List<List<string>> to List<string> [duplicate]

开发者 https://www.devze.com 2023-03-18 20:47 出处:网络
This question already has answers here: Closed 11 years ago. Possible Duplicate: Linq: List of lists to a long list
This question already has answers here: Closed 11 years ago.

Possible Duplicate:

Linq: List of lists to a long list

I have convert it using LINQ.

List<List<string>> to List<string>.

If the leaves overlap one. Must be In on开发者_开发问答e line.


input.SelectMany(l => l).Distinct().ToList();


Your question is a bit under specified.

input.SelectMany(list=>list).ToList()

This puts all strings that are part of any list into the result list. If you need only unique elements add .Distinct between the SelectMany and the ToList


List<List<string>> listOfLists = new List<List<string>>();
List<string> flattenedList = ListOfLists.SelectMany(x => x).ToList();
0

精彩评论

暂无评论...
验证码 换一张
取 消