共用方式為


編譯器錯誤 CS1667

更新:2007 年 11 月

錯誤訊息

屬性 (Attribute) 'attribute' 在屬性 (Property) 或事件存取子中無效。它只在 'declaration type' 宣告中有效。

如果您在屬性 (Property) 或事件存取子中使用屬性 (Attribute),但該屬性 (Attribute) 應在屬性 (Property) 或事件本身時,便會發生這個錯誤。可能發生這個錯誤的屬性 (Attribute) 包括:CLSCompliantAttributeConditionalAttributeObsoleteAttribute

範例

下列範例會產生 CS1670:

// CS1667.cs
using System;

public class C
{
    private int i;

    //Try this instead:
    //[Obsolete]
    public int ObsoleteProperty
    {
        [Obsolete]  // CS1667
        get { return i; }
        set { i = value; }
    }

    public static void Main()
    {
    }
}