开发者

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

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜