c# - What it the easiest way to make LINQ to process all collection at once? -
i have similar constructions:
var t = in enumerable.range(0,5) select num(i); console.writeline(t.count()); foreach (var item in t) console.writeline(item);
in case linq evaluate num()
function twice each element (one count() , 1 output). after such linq calls have declare new vatiable: var t2 = t.tolist();
is there better way this?
you can call tolist
without making separate variable:
var t = enumerable.range(0,5).select(num).tolist();
edit: or,
var t = enumerable.range(0,5).select(x => num(x)).tolist();
or even
var t = (from in enumerable.range(0,5) select num).tolist();
Comments
Post a Comment