编译器错误 CS0283
更新:2007 年 11 月
错误消息
不能将类型“type”声明为 const
常量声明中指定的类型必须是 byte、char、short、int、long、float、double、decimal、bool、string、枚举类型、或被赋予 null 值的引用类型。每个常数表达式产生的值必须属于目标类型,或者属于可隐式转换为目标类型的类型。
示例
下面的示例生成 CS0283。
// CS0283.cs
struct MyTest
{
}
class MyClass
{
// To resolve the error but retain the "const-ness",
// change const to readonly.
const MyTest test = new MyTest(); // CS0283
public static int Main() {
return 1;
}
}