編譯器錯誤 CS0616
更新:2007 年 11 月
錯誤訊息
'class' 不是屬性類別
嘗試在屬性 (Attribute) 區塊中使用非屬性類別。所有的屬性型別都必須繼承自 System.Attribute。
範例
下列範例會產生 CS0616:
// CS0616.cs
// compile with: /target:library
[CMyClass(i = 5)] // CS0616
public class CMyClass {}
下列範例顯示如何定義一個屬性:
// CreateAttrib.cs
// compile with: /target:library
using System;
[AttributeUsage(AttributeTargets.Class|AttributeTargets.Interface)]
public class MyAttr : Attribute
{
public int Name = 0;
public int Count = 0;
public MyAttr (int iCount, int sName)
{
Count = iCount;
Name = sName;
}
}
[MyAttr(5, 50)]
class Class1 {}
[MyAttr(6, 60)]
interface Interface1 {}