开发者

Multiple from clauses in LINQ

How can this LINQ query expression be re-expressed with extension meth开发者_Python百科od calls?

public static List<Tuple<int, int>> Concat()
{
    return (from x in Enumerable.Range(1, 3)
           from y in Enumerable.Range(4, 3)
           select new Tuple<int, int>(x, y)).ToList();
}


return Enumerable.Range(1, 3).SelectMany(x => Enumerable.Range(4, 3)
           .Select(y => new Tuple<int, int>(x, y))).ToList();

Your version looks more readable :-)


Enumerable.Range(1, 3).SelectMany(
    i => Enumerable.Range(4, 3),
    (i, j) => new Tuple<int, int>(i, j)
).ToList();
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜