• home
  • Email: trainings@synapseindia.careers



Understanding Attributes in C#

Jun 06, 2015

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. C# enables programmers to invent new kinds of declarative information, called attributes.Attributes provide a powerful method of associating declarative information with C# code (types, methods, properties, and so forth). Once associated with a program entity, the attribute can be queried at run time and used in any number of ways. Programmers can then attach attributes to various program entities, and retrieve attribute information in a run-time environment. 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. A best example of attribute is Obsolete which can be used along with method then it gives information to compiler for not using it and can give error also at compile time if it is used by developer.

SynapseIndia (CEO: Shamit Khemka)