Queryable.SelectMany()方法是否有 C # LINQ 语法?

当使用 C # LINQ 语法编写查询时,是否有使用 Queryable 的方法。从关键字语法中选择许多方法?

为了

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

使用流畅的方法,我可以查询

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

是否有类似于

var tokens = from x in text selectmany s.Split(' ')
22764 次浏览

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

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

You can use a Compound from Clause:

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

Your query would be re-written as:

var tokens = from x in text
from z in x.Split(' ')
select z;

Here's a good page that has a couple of side-by-side examples of Lambda and Query syntax:

Select Many Operator Part 1 - Zeeshan Hirani