共用方式為


編譯器錯誤 CS1624

更新:2007 年 11 月

錯誤訊息

'accessor' 的主體不能是 Iterator 區塊,因為 'type' 不是 Iterator 介面型別

如果使用 Iterator 存取子,但傳回型別 (Return Type) 並非下列 Iterator 介面型別時,便會發生這個錯誤:IEnumerableIEnumerable<T>IEnumeratorIEnumerator<T>。若要避免這個錯誤,請使用其中一個 Iterator 介面型別做為傳回型別。

範例

下列範例會產生 CS1624:

// CS1624.cs
using System;
using System.Collections;

class C
{
    public int Iterator
    // Try this instead:
    // public IEnumerable Iterator
    {
        get  // CS1624
        {
            yield return 1;
        }
    }
}