Comparing LINQ Query Syntax with the
1st and 2nd overload of LINQ 'SelectMany'
Example of getting all variations of 3 characters from 3 strings using LINQ:
- with LINQ query syntax
from x in "ABC"
from y in "123"
from z in "123"
select $"{x}{y}{z} ");
- with LINQ method syntax, using the 1st overload of 'SelectMany'
(only with collection selector, this needs an additional nested select)
"ABC".SelectMany(x => "123".Select(y => $"{x}{y}"))
.SelectMany(x => "123".Select(y => $"{x}{y} ")));
- with LINQ method syntax, using the 2nd overload of 'SelectMany'
(with collection selector and result selector)
"ABC".SelectMany(x => "123", (x, y) => $"{x}{y}")
.SelectMany(x => "123", (x, y) => $"{x}{y} "));