Note that there are some explanatory texts on larger screens.

plurals
  1. POLambda Expression using Foreach Clause
    primarykey
    data
    text
    <blockquote> <p><strong>Possible Duplicate:</strong><br> <a href="https://stackoverflow.com/questions/101265/why-is-there-not-a-foreach-extension-method-on-the-ienumerable-interface">Why is there not a ForEach extension method on the IEnumerable interface?</a> </p> </blockquote> <p><strong>EDIT</strong></p> <p>For reference, here's the blog post which eric referrrred to in the comments</p> <p><a href="http://blogs.msdn.com/ericlippert/archive/2009/05/18/foreach-vs-foreach.aspx" rel="nofollow noreferrer">http://blogs.msdn.com/ericlippert/archive/2009/05/18/foreach-vs-foreach.aspx</a></p> <p><strong>ORIG</strong></p> <p>More of a curiosity I suppose but one for the C# Specification Savants...</p> <p>Why is it that the ForEach() clause doesn't work (or isn't available) for use on IQueryable/IEnumerable result sets...</p> <p>You have to first convert your results ToList() or ToArray() Presumably theres a technical limitation to the way C# iterates IEnumerables Vs. Lists... Is it something to do with the Deferred Execution's of IEnumerables/IQuerable Collections. e.g.</p> <pre><code>var userAgentStrings = uasdc.UserAgentStrings .Where&lt;UserAgentString&gt;(p =&gt; p.DeviceID == 0 &amp;&amp; !p.UserAgentString1.Contains("msie")); //WORKS userAgentStrings.ToList().ForEach(uas =&gt; ProcessUserAgentString(uas)); //WORKS Array.ForEach(userAgentStrings.ToArray(), uas =&gt; ProcessUserAgentString(uas)); //Doesn't WORK userAgentStrings.ForEach(uas =&gt; ProcessUserAgentString(uas)); </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
 

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