Errore del compilatore CS1624

Aggiornamento: novembre 2007

Messaggio di errore

Il corpo di 'funzione di accesso' non può essere un blocco iteratore perché 'tipo' non è un tipo di interfaccia iteratore.
The body of 'accessor' cannot be an iterator block because 'type' is not an iterator interface type

Questo errore si verifica quando si utilizza una funzione di accesso all'iteratore ma il tipo restituito non è un tipo dell'interfaccia iteratore: IEnumerable, IEnumerable<T>, IEnumerator, IEnumerator<T>. Per correggere l'errore, utilizzare un tipo dell'interfaccia iteratore come tipo restituito.

Esempio

Il seguente codice di esempio genera l'errore CS1624:

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

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