SelectMany
SelectMany将序列的每个元素投影到 IEnumerable
static void Main()
{
string[] text = { "Albert was here",
"Burke slept late",
"Connor is happy" };
// SelectMany合并并返回一个新序列
var tt = text.SelectMany((s, index) => from ss in s.Split(' ')
select new { Word = ss, Index = index });
foreach (var n in tt)
Console.WriteLine("{0}:{1}", n.Word,n.Index);
}
运行结果为:
Albert:0
was:0
here:0
Burke:1
slept:1
late:1
Connor:2
is:2
happy:2