Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>OK, just tried it out and I see what you mean. That's painful! I suspect it has to do with the behind-the-scenes work the compiler does (creating nested classes and such) to implement the resumable state machine-type logic for <code>yield</code>. One way of getting around it (the way I originally tried your code) is to make the <code>Validate</code> method static, though obviously that's not great for the design.</p> <p>I think the reason the error message is so obtuse is some combination of:</p> <ol> <li>The generated classes don't exist in your source, so VS has no names by which to refer to them.</li> <li>IIRC, the names generated by the compiler contain characters illegal in C# identifiers, but valid in the underlying Framework type system.</li> </ol> <p>I don't have Reflector handy right now, so can't confirm, but if you're feeling like a spot of light masochism, reflect on your assembly and take a look at the code the compiler writes to let us mere mortals use nice syntactic sugar like <code>yield return</code> :) There's lots of information available on the web on how exactly it all works.</p> <p><strong>Edit:</strong> after a little more searching, a couple of the better ones:<br> <a href="http://blogs.msdn.com/b/ericlippert/archive/tags/iterators/" rel="noreferrer">http://blogs.msdn.com/b/ericlippert/archive/tags/iterators/</a><br> <a href="http://csharpindepth.com/Articles/Chapter6/IteratorBlockImplementation.aspx" rel="noreferrer">http://csharpindepth.com/Articles/Chapter6/IteratorBlockImplementation.aspx</a></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