开发者

Multiple from clauses in LINQ

开发者 https://www.devze.com 2022-12-10 05:31 出处:网络
How can this LINQ query expression be re-expressed with extension meth开发者_Python百科od calls?

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

精彩评论

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