Attribute: Difference between revisions

From MXMS Wiki
Jump to navigationJump to search
Created page with "An attribute is a declarative tag used to add metadata, or extra information, to program elements such as assemblies, classes, methods, and properties. This metadata can be read at compile time or retrieved at run time using a technique called reflection to dynamically alter program behavior or provide additional context."
 
No edit summary
Line 1: Line 1:
An attribute is a declarative tag used to add metadata, or extra information, to program elements such as assemblies, classes, methods, and properties. This metadata can be read at compile time or retrieved at run time using a technique called reflection to dynamically alter program behavior or provide additional context.
In the C# programming language, attributes are metadata attached to a field or a block of code like assemblies, members and types, and are equivalent to annotations in Java. Attributes are accessible to both the compiler and programmatically through reflection. In contrast, properties, in C# terminology, are members of a class which syntactically are used like instance (or class) variables, but are implemented as a pair of getter/setter functions. (In the absence of a setter, properties are read-only.)

Revision as of 16:20, 16 March 2026

In the C# programming language, attributes are metadata attached to a field or a block of code like assemblies, members and types, and are equivalent to annotations in Java. Attributes are accessible to both the compiler and programmatically through reflection. In contrast, properties, in C# terminology, are members of a class which syntactically are used like instance (or class) variables, but are implemented as a pair of getter/setter functions. (In the absence of a setter, properties are read-only.)