编译器错误 CS0616
更新:2007 年 11 月
错误消息
“class”不是属性类
试图在属性块中使用非属性类。所有属性类型都必须从 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 {}