Using multiple yield statements in an iterator

static void Main ()
{
  foreach (string s in getty())
    Console.Write (s + " ") // There you go
}
 
static IEnumerable<string> getty()
{
  yield return "There";
   yield return "you";
   yield return "go";
}

Enjoyed this post? Share it!

 

Leave a comment

Your email address will not be published.