0

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;

1 Answer 1

2
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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.