컴파일러 오류 CS0266
암시적으로 'type1' 형식을 'type2' 형식으로 변환할 수 없습니다. 명시적 변환이 있습니다. 캐스트가 있는지 확인하세요.
이 오류는 코드에서 암시적으로 변환할 수 없는 두 형식 간에 변환하려고 하지만 명시적 변환을 사용할 수 있는 경우 발생합니다. 자세한 내용은 캐스팅 및 형식 변환을 참조하세요.
다음 코드는 CS0266을 생성하는 예제입니다.
// CS0266.cs
class MyClass
{
public static void Main()
{
// You cannot implicitly convert a double to an integer.
double d = 3.2;
// The following line causes compiler error CS0266.
int i1 = d;
// However, you can resolve the error by using an explicit conversion.
int i2 = (int)d;
// You cannot implicitly convert an object to a class type.
object obj = new MyClass();
// The following assignment statement causes error CS0266.
MyClass myClass = obj;
// You can resolve the error by using an explicit conversion.
MyClass c = (MyClass)obj;
// You cannot implicitly convert a base class object to a derived class type.
MyClass mc = new MyClass();
DerivedClass dc = new DerivedClass();
// The following line causes compiler error CS0266.
dc = mc;
// You can resolve the error by using an explicit conversion.
dc = (DerivedClass)mc;
}
}
class DerivedClass : MyClass
{
}
GitHub에서 Microsoft와 공동 작업
이 콘텐츠의 원본은 GitHub에서 찾을 수 있으며, 여기서 문제와 끌어오기 요청을 만들고 검토할 수도 있습니다. 자세한 내용은 참여자 가이드를 참조하세요.
.NET