| 1. |
What Is Attribute In C#? |
|
Answer» An attributes is a declarative tag that is used to convey information about the behaviors of various elements (classes, methods, ASSEMBLIES, structures, enumerators, etc). it is access at compile TIME or run-time. Attributes are declare with a square brackets [] which is places above the elements. [Obsolete(“Don’t use Old method, please use New method”, true)] For example CONSIDER the bellow CLASS. If we call the old method it will through error message. PUBLIC class myClass { [Obsolete("Don't use Old method, please use New method", true)] public string Old() { return "Old"; } public string New() { return "New"; } } myClass omyClass = new myClass(); omyClass.Old(); An attributes is a declarative tag that is used to convey information about the behaviors of various elements (classes, methods, assemblies, structures, enumerators, etc). it is access at compile time or run-time. Attributes are declare with a square brackets [] which is places above the elements. [Obsolete(“Don’t use Old method, please use New method”, true)] For example consider the bellow class. If we call the old method it will through error message. public class myClass { [Obsolete("Don't use Old method, please use New method", true)] public string Old() { return "Old"; } public string New() { return "New"; } } myClass omyClass = new myClass(); omyClass.Old(); |
|