working pattern of yield return

前端 未结 4 1468
一整个雨季
一整个雨季 2021-02-07 22:43

When i have a code block

static void Main()
{

  foreach (int i in YieldDemo.SupplyIntegers())
  {
    Console.WriteLine(\"{0} is consumed by foreach iteration\         


        
4条回答
  •  猫巷女王i
    2021-02-07 22:55

    It's just a syntax sugar, .net generates IEnumerator class for you and implements MoveNext, Current and Reset methods, than generates IEnumarable class GetEnumerator of which returns that IEnumerator, you can see that magic classes by .net reflector or ildasm.

    Also see here

提交回复
热议问题