Tuesday 3 June 2014

how to used the YIELD keyword.

public  class C
    {
     
     public IEnumerable< int> yieldMethod()
      {
         int i=1;
          for (i = 1; i < 5; i++)
                yield return i;
       }
   }

void .fun()
        {
            C obj1 = new C(10);
            foreach (var item in obj1.yieldMethod())
            {
                Console.WriteLine(item);
            }
           
     }

Output:--
1
2
3
4

No comments:

Post a Comment