Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Compiler Error CS0266
Collapse the table of content
Expand the table of content

Compiler Error CS0266

Cannot implicitly convert type 'type1' to 'type2'. An explicit conversion exists (are you missing a cast?)

This error occurs if you have code that tries to convert two types that cannot be implicitly converted, such as in an assignment of a base type to a derived type that is missing an explicit cast. For more information, see Conversion Operators (C# Programming Guide).

The following sample generates CS0266:

// CS0266.cs
class MyClass
{
    public static void Main()
    {
        object obj = "MyString";
        // Cannot implicitly convert 'object' to 'MyClass'
        MyClass myClass = obj;  // CS0266
        // Try this line instead
        // MyClass c = ( MyClass )obj;
    }
}

Community Additions

ADD
Show:
© 2015 Microsoft