[Note: Much of the C# language enables the programmer to specify declarative
information about the
entities defined in the program. For example, the accessibility of a method
in a class is specified by
decorating it with the method-modifiers public, protected, internal, and
private. end note]
C# enables programmers to invent new kinds of declarative information,
called attributes. Programmers can
then attach attributes to various program entities, and retrieve attribute
information in a run-time
environment. [Note: For instance, a framework might define a HelpAttribute
attribute that can be placed
on certain program elements (such as classes and methods) to provide a
mapping from those program
elements to their documentation. end note]
Attributes are defined through the declaration of attribute classes (§24.1),
which may have positional and
named parameters (§24.1.2). Attributes are attached to entities in a C#
program using attribute specifications
(§24.2), and can be retrieved at run-time as attribute instances (§24.3).
information about the
entities defined in the program. For example, the accessibility of a method
in a class is specified by
decorating it with the method-modifiers public, protected, internal, and
private. end note]
C# enables programmers to invent new kinds of declarative information,
called attributes. Programmers can
then attach attributes to various program entities, and retrieve attribute
information in a run-time
environment. [Note: For instance, a framework might define a HelpAttribute
attribute that can be placed
on certain program elements (such as classes and methods) to provide a
mapping from those program
elements to their documentation. end note]
Attributes are defined through the declaration of attribute classes (§24.1),
which may have positional and
named parameters (§24.1.2). Attributes are attached to entities in a C#
program using attribute specifications
(§24.2), and can be retrieved at run-time as attribute instances (§24.3).
本文介绍了C#中属性的概念及其使用方式。属性允许程序员为程序元素定义新的声明信息,并能在运行时环境中检索这些信息。文章还举例说明了如何通过自定义属性来增强程序的描述性和功能性。

被折叠的 条评论
为什么被折叠?



