performance - Does chaining LINQ statements result in multiple iterations? -


does chaining linq statements result in multiple iterations?

for example, let's want filter data clause, , on matches sum:

int total = data.where(item => item.alpha == 1 && item.beta == 2)     .sum(item => item.qty); 

does result in single interation of data, such equivalent this?

int total = 0; foreach (var item in data)     if (item.alpha == 1 && item.beta == 2)         total += 1; 

or, iterate on data once, , results of where second time sum?

the statements in linq streamed, where not run until sum enumerates through values. means items data enumerated single time.

basically, where method creates new ienumerable<t>, doesn't enumerate through data. sum foreach on ienumerable<t> where, in turn pulls items through where sequence 1 @ time.


Comments

Popular posts from this blog

java - Run a .jar on Heroku -

java - Jtable duplicate Rows -

validation - How to pass paramaters like unix into windows batch file -