如何在C#中使用属性
属性是一个声明性标记,用于向运行时传达有关程序中各种元素(例如类,方法,结构,枚举器,程序集等)的行为的信息。您可以使用属性将声明性信息添加到程序中。声明性标记由放置在所使用元素上方的方括号([])表示。
以下是属性的语法-
[attribute(positional_parameters, name_parameter = value, ...)] Element
.NetFramework提供了两种类型的属性:预定义属性和自定义生成的属性。
让我们看看如何声明自定义属性-
//a custom attribute BugFix to be assigned to a class and its members [AttributeUsage( AttributeTargets.Class | AttributeTargets.Constructor | AttributeTargets.Field | AttributeTargets.Method | AttributeTargets.Property, AllowMultiple = true)] public class DeBugInfo : System.Attribute
热门推荐
10 祝女儿简短祝福语大全
11 大学新年祝福语简短创意
12 元旦适合的祝福语简短
13 朋友出远门祝福语简短
14 初六简短的祝福语
15 祝男孩生日祝福语简短
16 同事调离的祝福语简短
17 拜年红包的祝福语简短
18 妈妈生日祝福语简短励志