What is the attribute in C# ?


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#.

attribute

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.

Attribute1

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

Attribute2

Now end user developer cannot use the “CalculateAmt” method in his application.

Summary

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.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: