Is there a C# LINQ syntax for the Queryable.SelectMany() method?

BrianCooksey picture BrianCooksey · Jun 20, 2011 · Viewed 19.3k times · Source

When writing a query using C# LINQ syntax, is there a way to use the Queryable.SelectMany method from the keyword syntax?

For

string[] text = { "Albert was here", 
                  "Burke slept late", 
                  "Connor is happy" };

Using fluent methods I could query

var tokens = text.SelectMany(s => s.Split(' '));

Is there a query syntax akin to

var tokens = from x in text selectmany s.Split(' ')

Answer

driis picture driis · Jun 20, 2011

Yes, you just repeat the from ... in clause:

var words = from str in text
            from word in str.Split(' ')
            select word;