Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

c#

linq

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 one line.

like image 999
Rafal T Avatar asked Jul 07 '11 11:07

Rafal T


People also ask

Does converting list to Set remove duplicates?

When you convert a list into a set, all the duplicates will be removed. The set can then be converted back into a list with list() . The drawback of this method is that the use of set() also changes the original list order, which is not restored after it is converted back into a list.


2 Answers

input.SelectMany(l => l).Distinct().ToList();
like image 95
Arcturus Avatar answered Sep 24 '22 12:09

Arcturus


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

like image 33
CodesInChaos Avatar answered Sep 22 '22 12:09

CodesInChaos