編譯器錯誤 CS0039
更新:2007 年 11 月
錯誤訊息
無法使用參考轉換、boxing 轉換、unboxing 轉換、wrapping 轉換或 null 型別轉換來將型別 'type1' 轉換成 'type2'
繼承、參考轉換及 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
}
}