Compiler Error CS0039
无法通过引用转换、装箱转换、取消装箱转换、包装转换或 Null 类型转换将类型“type1”转换为“type2”
继承、引用转换和装箱转换允许使用 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
}
}