c# - Translating query comprehension to Enumerable extension methods in LINQ -
how translate following query functional calls? know compiler behind scenes don't know how view result
var query = item in enumerable.range(0, 10) item2 in enumerable.range(item, 10) item3 in enumerable.range(item2, 10) select new { item, item2, item3 };
in case, uses selectmany
, , concept called transparent identifiers preserve existing range variables. query translate to:
var query = enumerable.range(0, 10) .selectmany(item => enumerable.range(item, 10), (item, item2) => new { item, item2 }) .selectmany(z => enumerable.range(z.item2, 10), (z, item3) => new { z.item, z.item2, item3 });
(in case z
transparent identifier. if there'd been where
clause or other select
after last from
clause, transparent identifier have been introduced.)
the translations described in c# language specification, section 7.16.
Comments
Post a Comment