共用方式為


編譯器錯誤 CS1631

更新:2007 年 11 月

錯誤訊息

無法在 catch 子句主體中使用 yield 產生值

catch 子句主體內部不允許 yield 陳述式。若要避免這個錯誤,請將 yield 陳述式移出 catch 子句主體之外。

下列範例會產生 CS1631:

// CS1631.cs
using System;
using System.Collections;

public class C : IEnumerable
{
   public IEnumerator GetEnumerator() 
   {
      try
      {
      }
      catch(Exception e)
      {
        yield return this;  // CS1631
      }
   }  

   public static void Main() 
   {
   }
}