• ​yeild return​​，把程序控制权交回调用者并保留本地状态，调用者拿到返回的值继续往后执行。
• ​yeild break​​，用于告诉程序当前序列已经结束，相当于正常代码块的 return 语句（迭代器中直接使用 return 是非法的）。

IEnumerable<int> Fibonacci(int count){  int prev = 1;  int curr = 1;  for (int i = 0; i < count; i++)  {    yield return prev;    int temp = prev + curr;    prev = curr;    curr = temp;  }}void Main(){  foreach (int term in Fibonacci(10))  {    Console.WriteLine(term);  }}

11235813213455

int[] numbers = { 1, 2, 3, 4, 5 };IEnumerator enumerator = numbers.GetEnumerator();while (enumerator.MoveNext()){  Console.WriteLine(enumerator.Current);}

int[] numbers = { 1, 2, 3, 4, 5 };foreach (int number in numbers){  Console.WriteLine(number);}

public class CoffeeCollection : IEnumerable{  private CoffeeEnumerator enumerator;  public CoffeeCollection()  {    enumerator = new CoffeeEnumerator();  }  public IEnumerator GetEnumerator()  {    return enumerator;  }  public class CoffeeEnumerator : IEnumerator  {    string[] items = new string[3] { "espresso", "macchiato", "latte" };    int currentIndex = -1;    public object Current    {      get      {        return items[currentIndex];      }    }    public bool MoveNext()    {      currentIndex++;      if (currentIndex < items.Length)      {        return true;      }      return false;    }    public void Reset()    {      currentIndex = 0;    }  }}

public static void Main(string[] args){  foreach (var coffee in new CoffeeCollection())  {    Console.WriteLine(coffee);  }}

if(enumerable.Count() > 0){  // 集合中有元素}

if(enumerable.GetEnumerator().MoveNext()){  // 集合中有元素}

if(enumerable.Any()){  // 集合中有元素}