Erreur du compilateur CS0448
Mise à jour : novembre 2007
Message d'erreur
Le type de retour pour l'opérateur ++ ou -- doit être le type conteneur ou dérivé du type conteneur
The return type for ++ or -- operator must be the containing type or derived from the containing type
Lorsque vous substituez les opérateurs ++ ou --, ils doivent retourner le même type que le type conteneur ou retourner un type qui est dérivé du type conteneur.
Exemple
L'exemple suivant génère l'erreur 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() {}
}
L'exemple suivant génère l'erreur 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() {}
}