Compiler Error CS0030

Cannot convert type 'type' to 'type'

You must provide conversion routines to support certain operator overloads. For more information, see Conversion Operators (C# Programming Guide).

The following sample generates CS0030:

// CS0030.cs
namespace Conversions
{
    public class MyType
    {
        // The following operators define conversions from an integer to
        // MyType and from MyType to an integer.
        /*
        public static implicit operator MyType(int anArg)
        {
           return null;
        }

        public static implicit operator int(MyType anArg)
        {
           return 0;
        }
        */

        // The following operator definition causes a compiler error because the
        // conversion operator that converts from type int to type MyType is 
        // commented out.   
        public static MyType operator ++(MyType aa)
        {
            return (MyType)0;   // CS0030
            // Uncomment the conversion routines to resolve the error.
        }

        public static void Main()
        {
        }
    }
}

Change History

Date

History

Reason

July 2009

Expanded the example.

Customer feedback.