共用方式為


編譯器錯誤 CS1625

更新:2007 年 11 月

錯誤訊息

yield 不能在 finally 子句的主體中

yield 陳述式不能位於 finally 子句的主體中。若要避免這個錯誤,請將 yield 陳述式移出 finally 子句。

下列範例會產生 CS1625:

// CS1625.cs
using System.Collections;

class C : IEnumerable
{
   public IEnumerator GetEnumerator()
   {
      try
      {
      }
      finally
      {
        yield return this;  // CS1625
      }
   }
}

public class CMain
{
   public static void Main() { }
}