Läs på engelska

Dela via


Kompilatorfel CS0579

Duplicera attributet "attribut"

Det går inte att ange samma attribut mer än en gång om inte attributet anger AllowMultiple=true i attributetUsage.

Exempel

I följande exempel genereras 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()  
    {  
    }  
}