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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.