Edit

Share via


Compiler Error CS1031

Type expected

A type has not been specified where expected, when overloading an operator.
Missing type in this case means that there's no type given for the return type of the overloaded operator. This error shouldn't be confused with missing generic type parameter.

Example

The following sample generates CS1031:

namespace x
{
    public class I
    {
    }

    public class A
    {  
        public static operator +(A a)    // CS1031 - Overloaded operator missing a type
        {
            return new I();
        }

        public static I operator +(A a)  // Correct - type was specified
        {
            return new I();
        }
    }
}