9

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.

4
  • 1
    Can you provide an example? I'm not sure if I understand what you need. Commented Jul 7, 2011 at 11:48
  • "If the leaves overlap one" what do you mean by that? Do you want to simply flatten the list, or do you only want distinct elements, or something entirely different? Commented Jul 7, 2011 at 11:51
  • SelectMany is what exactly I was looking for. Thank you all. Commented Jul 7, 2011 at 11:54
  • When I typed differently I found even otherwise. stackoverflow.com/questions/462879/… I apologize for repeating questions Commented Jul 7, 2011 at 11:59

3 Answers 3

18
input.SelectMany(l => l).Distinct().ToList();
Sign up to request clarification or add additional context in comments.

Comments

5

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

Comments

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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.