Attribute is the piece of information which is generally used to pass message to developer whenever he/she is going to use that class, method or properties in his application.
Suppose you have created some .dll or Framework which one you have exposed to developer. Now you have written some new method with new features. Now you want to inform to developers that “please use the new method for better performance”. Then you can take help of attribute in C#.
Generally we will get this message in .net F/w if you will use some old method which is currently no more in use.
For using the attribute we can use Obsolete keyword and pass the required message to developer as per as given below code.
Note: If we have to completely restrict the end user to use that method in his application then you can pass true in obsolete method as given below images
Now end user developer cannot use the “CalculateAmt” method in his application.
In the above demo, we saw that how to use attribute in C#. It is very handy process to pass message to developer if you are going remove the old method.