Nota
L'accesso a questa pagina richiede l'autorizzazione. È possibile provare ad accedere o modificare le directory.
L'accesso a questa pagina richiede l'autorizzazione. È possibile provare a modificare le directory.
Aggiornamento: novembre 2007
Messaggio di errore
Il tipo restituito dall'operatore ++ o -- deve essere il tipo che lo contiene o un tipo derivato da quest'ultimo.
The return type for ++ or -- operator must be the containing type or derived from the containing type
Quando viene eseguito l'override dell'operatore ++ o --, deve essere restituito un tipo identico a quello che lo contiene oppure un tipo derivato da quest'ultimo.
Esempio
Il seguente codice di esempio genera l'errore CS0448:
// CS0448.cs
class C5
{
public static int operator ++(C5 c) { return null; } // CS0448
public static C5 operator --(C5 c) { return null; } // OK
public static void Main() {}
}
Il seguente codice di esempio genera l'errore CS0448:
// CS0448_b.cs
public struct S
{
public static S? operator ++(S s) { return new S(); } // CS0448
public static S? operator --(S s) { return new S(); } // CS0448
}
public struct T
{
// OK
public static T operator --(T t) { return new T(); }
public static T operator ++(T t) { return new T(); }
public static T? operator --(T? t) { return new T(); }
public static T? operator ++(T? t) { return new T(); }
public static void Main() {}
}