Click here to Skip to main content
15,881,455 members
Home / Discussions / C#
   

C#

 
AnswerRe: import/Export Xml into a hastable Pin
Gareth H1-May-08 7:55
Gareth H1-May-08 7:55 
AnswerRe: import/Export Xml into a hastable Pin
Anthony Mushrow1-May-08 8:12
professionalAnthony Mushrow1-May-08 8:12 
Questionyield return Pin
George_George1-May-08 4:23
George_George1-May-08 4:23 
AnswerRe: yield return Pin
led mike1-May-08 4:41
led mike1-May-08 4:41 
GeneralRe: yield return Pin
George_George1-May-08 4:45
George_George1-May-08 4:45 
GeneralRe: yield return Pin
User 66581-May-08 6:32
User 66581-May-08 6:32 
GeneralRe: yield return Pin
George_George1-May-08 21:58
George_George1-May-08 21:58 
GeneralRe: yield return Pin
Simon P Stevens1-May-08 9:42
Simon P Stevens1-May-08 9:42 
I got interested in this and investigated, and wrote a massive reply about what was happening in the IL, all commented and everything, then it didn't post properly and I lost it.

Basically, it compiles it to a private that inherits from IEnumerator inside your class. It moves your code into the MoveNext routine of the private class, and splits it up with a case statement so each time MoveNext is called, it does the next bit of your routine up to the next yield return statement, and then sets the Current property of the private to be your yield return value. This means when you stick your class in a foreach loop, the foreach loop calls GetEnumerator, which returns the private class, and then calls MoveNext and keeps looking at the Current property.

Just write a simple class that implements IEnumerable, and a GetEnumerator() method, compile it, and take a look with reflector, you'll see what I'm babbling on about.

Simon

GeneralRe: yield return Pin
George_George1-May-08 21:57
George_George1-May-08 21:57 
GeneralRe: yield return Pin
Simon P Stevens2-May-08 9:33
Simon P Stevens2-May-08 9:33 
GeneralRe: yield return Pin
George_George2-May-08 21:24
George_George2-May-08 21:24 
Question1-Wire iButtons [modified] Pin
MarkB7771-May-08 3:32
MarkB7771-May-08 3:32 
QuestionFinalization and Performance Pin
George_George1-May-08 3:20
George_George1-May-08 3:20 
AnswerRe: Finalization and Performance Pin
Christian Graus1-May-08 3:34
protectorChristian Graus1-May-08 3:34 
GeneralRe: Finalization and Performance Pin
George_George1-May-08 3:47
George_George1-May-08 3:47 
GeneralRe: Finalization and Performance Pin
Christian Graus1-May-08 3:56
protectorChristian Graus1-May-08 3:56 
GeneralRe: Finalization and Performance Pin
George_George1-May-08 4:10
George_George1-May-08 4:10 
GeneralRe: Finalization and Performance Pin
N a v a n e e t h1-May-08 6:07
N a v a n e e t h1-May-08 6:07 
GeneralRe: Finalization and Performance Pin
George_George1-May-08 21:19
George_George1-May-08 21:19 
GeneralRe: Finalization and Performance Pin
N a v a n e e t h1-May-08 22:59
N a v a n e e t h1-May-08 22:59 
GeneralRe: Finalization and Performance Pin
George_George2-May-08 2:43
George_George2-May-08 2:43 
AnswerRe: Finalization and Performance PinPopular
Mike Dimmick1-May-08 6:04
Mike Dimmick1-May-08 6:04 
GeneralRe: Finalization and Performance Pin
N a v a n e e t h1-May-08 6:41
N a v a n e e t h1-May-08 6:41 
GeneralRe: Finalization and Performance Pin
Guffa1-May-08 9:29
Guffa1-May-08 9:29 
GeneralRe: Finalization and Performance Pin
George_George1-May-08 21:27
George_George1-May-08 21:27 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.