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;
asked Dec 25, 2013 at 0:09

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.

i3arnon
117k33 gold badges334 silver badges360 bronze badges
answered Dec 25, 2013 at 0:20
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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.