Csharp/CSharp Tutorial/Attribute/AttributeUsage
AttributeUsage
The AttributeUsage attribute specifies the types of items to which an attribute can be applied.
AttributeUsage is another name for the System.AttributeUsageAttribute class.
AttributeUsage has the following constructor:
<source lang="csharp">AttributeUsage(AttributeTargets item)</source>
Define a attribute for remark
<source lang="csharp">using System; [AttributeUsage(AttributeTargets.All)] public class MyAttribute : Attribute {
string remark; public MyAttribute(string comment) { remark = comment; } public string Remark { get { return remark; } }
}</source>