Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Well, when we are talking bout delegate usage, there shouldn't be any difference between lambda and anonymous methods -- they are the same, just with different syntax. And named methods (used as delegates) are also identical from the runtime's viewpoint. The difference, then, is between using delegates, vs. inline code - i.e.</p> <pre><code>list.ForEach(s=&gt;s.Foo()); // vs. foreach(var s in list) { s.Foo(); } </code></pre> <p>(where I would expect the latter to be quicker)</p> <p>And equally, if you are talking about anything <em>other</em> than in-memory objects, lambdas are one of your most powerful tools in terms of maintaining type checking (rather than parsing strings all the time).</p> <p>Certainly, there are cases when a simple <code>foreach</code> with code will be faster than the LINQ version, as there will be fewer invokes to do, and invokes cost a small but measurable time. However, in many cases, the code is simply not the bottleneck, and the simpler code (especially for grouping, etc) is worth a lot more than a few nanoseconds.</p> <p>Note also that in .NET 4.0 there are <a href="http://marcgravell.blogspot.com/2008/11/future-expressions.html" rel="noreferrer">additional <code>Expression</code> nodes</a> for things like loops, commas, etc. The language doesn't support them, but the runtime does. I mention this only for completeness: I'm certainly not saying you should use manual <code>Expression</code> construction where <code>foreach</code> would do!</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload