Home > Article > Backend Development > How to use properties in C#
Attributes are declarative tags used to communicate to the runtime information about the behavior of various elements in a program (such as classes, methods, structures, enumerators, assemblies, etc.) information. You can add declarative information to your program by using properties. Declarative markup is represented by square brackets ([ ]) placed above the element it is used for.
The following is the syntax of properties:
[attribute(positional_parameters, name_parameter = value, ...)] Element
.Net Framework provides two types of properties: predefined properties and custom build properties.
Let’s see how to declare custom properties -
//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
The above is the detailed content of How to use properties in C#. For more information, please follow other related articles on the PHP Chinese website!