컴파일러 오류 CS0039
업데이트: 2007년 11월
오류 메시지
참조 변환, boxing 변환, unboxing 변환, 래핑 변환 또는 null 형식 변환을 통해 'type1' 형식을 'type2'(으)로 변환할 수 없습니다.
Cannot convert type 'type1' to 'type2' via a reference conversion, boxing conversion, unboxing conversion, wrapping conversion, or null type conversion
상속, 참조 변환 및 boxing 변환에서는 as(C# 참조) 연산자를 사용하여 변환할 수 있습니다. 자세한 내용은 변환 연산자(C# 프로그래밍 가이드)를 참조하십시오.
예제
다음 예제에서는 CS0039 오류가 발생하는 경우를 보여 줍니다.
// CS0039.cs
using System;
class A
{
}
class B: A
{
}
class C: A
{
}
class M
{
static void Main()
{
A a = new C();
B b = new B();
C c;
// This is valid; there is a built-in reference
// conversion from A to C.
c = a as C;
//The following generates CS0039; there is no
// built-in reference conversion from B to C.
c = b as C; // CS0039
}
}