編譯器錯誤 CS0283
更新:2007 年 11 月
錯誤訊息
型別 'type' 無法宣告為常數
常數宣告中指定的型別必須是 byte、char、short、int、long、float、double、decimal、bool、string、列舉型別 (Enum Type) 或指派了 null 值的參考型別 (Reference Type)。每個常數運算式都必須產生一個目標型別的數值,或是可透過隱含轉換而轉換成目標型別的型別數值。
範例
下列範例會產生 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;
}
}