C#LINQSelectMany
Join

SelectManyLINQ

First

Projects each element to an IEnumerable and flattens the resulting sequences.

Syntax

source.SelectMany(selector)

Example

Enter values below to update the example in real time.

var
sentences
new
words
SelectMany
Split
ToList
Console
WriteLine
string
Hello
World
Foo
Bar
var sentences = new[] { "Hello World", "Foo Bar" };
var words = sentences.SelectMany(s => s.Split(' ')).ToList();
Console.WriteLine(string.Join(", ", words));
// Hello, World, Foo, Bar