編譯器錯誤 CS1959
更新:2007 年 11 月
錯誤訊息
'name' 屬於型別 'type'。常數宣告中指定的型別必須為 sbyte、byte、short、ushort、int、uint、long、ulong、char、float、double、decimal、bool、string、列舉型別或參考型別。
允許出現在 Const 宣告中的型別僅限此訊息所描述的型別。
若要修正這個錯誤
- 使用允許的型別宣告常數。
範例
下列程式碼會因為 null 不是型別而產生 CS1959。
// cs1959.cs
class Program
{
static void Test<T>() where T : class
{
const T x = null; // CS1959
}
}