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
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
MarcinJuraszek
126k15 gold badges200 silver badges267 bronze badges
Sign up to request clarification or add additional context in comments.
Comments
lang-cs