共用方式為


編譯器錯誤 CS0579

更新:2007 年 11 月

錯誤訊息

'attribute' 屬性重複

除非屬性 (Attribute) 在其 AttributeUsage 中指定了 AllowMultiple=true,否則相同的屬性不可以指定超過一次。

範例

下列範例會產生 CS0579:

// 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()
    {
    }
}