编译器错误 CS1624
更新:2007 年 11 月
错误消息
“accessor”体不能是迭代器块,因为“type”不是迭代器接口类型
当使用了迭代器访问器,但返回类型不是以下迭代器接口类型之一时会发生此错误:IEnumerable、IEnumerable<T>、IEnumerator 和 IEnumerator<T>。若要避免此错误,请将其中一个迭代器接口类型用作返回类型。
示例
下面的示例生成 CS1624:
// CS1624.cs
using System;
using System.Collections;
class C
{
public int Iterator
// Try this instead:
// public IEnumerable Iterator
{
get // CS1624
{
yield return 1;
}
}
}