Error del compilador CS0448
Actualización: noviembre 2007
Mensaje de error
El tipo de valor devuelto para el operador ++ o -- debe ser el tipo contenedor o derivarse de éste
The return type for ++ or -- operator must be the containing type or derived from the containing type
Cuando se reemplazan los operadores ++ o --, deben devolver el mismo tipo que el tipo contenedor o devolver otro tipo que se derive de él.
Ejemplo
El código siguiente genera el error 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() {}
}
El código siguiente genera el error 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() {}
}