Now, one thing that you should be aware of is the concept called deferred execution. So, to see what that means, take a look at what follows.
Imagine that I place a break point right at the foreach(string formattedSalary in salResults)
line. Then, select Step Into
from the Debug
menu and click on the Show
button. Note how each line runs consecutively (the elapsed time in ms appears after each line). You should see how it's going into it; how it's running.
One thing that you should be aware of with LINQ is the concept of deferred execution, which means that, salResults
actually runs, as you can see, so it's a query variable essentially. It runs when you iterate over it using a foreach
construct, as shown in the following code block, not when you write it in the preceding IEnumerable
block. It doesn't run then. It runs when you iterate over it. Otherwise, your program will potentially carry huge amounts of information in these query results. So, that's about deferred...