更新:2007 年 11 月
错误消息
无法在包含 catch 子句的 try 块体内生成值如果有一个 catch 子句与 try 块关联,该 try 块内不允许有 yield 语句。若要避免此错误,请将 yield 语句移到 catch 子句的外部。
下面的示例生成 CS1626:
复制代码 | |
---|---|
// CS1626.cs using System.Collections; class C : IEnumerable { public IEnumerator GetEnumerator() { try { yield return this; // CS1626 } catch { } } } public class CMain { public static void Main() { } } |