Convert List<List<string>> to List<string> [duplicate]
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();
精彩评论