Errore del compilatore CS1622

Aggiornamento: novembre 2007

Messaggio di errore

Impossibile restituire un valore da un iteratore. Utilizzare l'istruzione yield return per restituire un valore o l'istruzione yield break per terminare l'iterazione.
Cannot return a value from an iterator. Use the yield return statement to return a value, or yield break to end the iteration.

Un iteratore è un funzione speciale che restituisce un valore mediante l'istruzione yield, anziché return. Per ulteriori informazioni, vedere iteratori.

Il seguente codice di esempio genera l'errore CS1622:

// CS1622.cs
// compile with: /target:library
using System.Collections;

class C : IEnumerable
{
   public IEnumerator GetEnumerator()
   {
      return (IEnumerator) this;  // CS1622
      yield return this;   // OK
   }
}