使用英语阅读

通过


编译器错误 CS0579

“attribute”属性重复

不可多次指定相同的属性,除非该属性在其 AttributeUsage 中指定 AllowMultiple=true。

示例

下面的示例生成 CS0579。

C#
// CS0579.cs  
using System;  
public class MyAttribute : Attribute  
{  
}  
  
[AttributeUsage(AttributeTargets.All,AllowMultiple=true)]  
public class MyAttribute2 : Attribute  
{  
}  
  
public class z  
{  
    [MyAttribute, MyAttribute]     // CS0579  
    public void zz()  
    {  
    }  
  
    [MyAttribute2, MyAttribute2]   // OK  
    public void zzz()  
    {  
    }  
  
    public static void Main()  
    {  
    }  
}