简体   繁体   中英

LINQ query in lambda syntax

What would be the proper way to write this query with lambda syntax?

var palindromes = from i in Enumerable.Range(100, 9900)
                  from j in Enumerable.Range(100, 9900)
                  let product = (i * j)
                  where product.ToString() == new string(product.ToString().Reverse().ToArray())
                  orderby product
                  select product;
var palindromes = Enumerable.Range(100, 9900)
    .SelectMany(
        i => Enumerable.Range(100, 9900),
        (i, j) => i * j)
    .Where(p => /* where condition */)
    .OrderBy(p => p);

That's not exactly how compiler will transform your query, but result should be the same.

You can check rules compiler follows when transforming syntax query to method invokaction in c# specification .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM