Introduction
In this blog, we are discussing how we can mark the method as deprecated, with the help of a simple program we can understand: method deprecation.
What is method deprecation?
I have created a console application with a simple class. In the class, I have two methods, those are addition and an improvised method of addition or the existing method. Now you want to tell your developer who is consuming the method addition instead of the addition method, and from now on it will consume improvised addition method.
- public void adition()
- {
- // intially created method , consumed by developers
- }
- public void improvised_adition()
- {
- // imrovised the addition method , for example may code fine tuneing.
- }
Now the question is, how to say the method is deprecated?
It is very simple-- please use the obsolete attribute. Please check the below code sample.
- [Obsolete] // using attribute.
- public void adition()
- {
- // intially created method , consumed by developers
- }
Do you think this is meaningful?
We can issue the proper message to the developer. Please check the below code modification.
- [Obsolete("adition method logic is re-wriitened , now onwords use improvised_adition")]
- public void adition()
- {
- // intially created method , consumed by developers
- }
Now the situation is different -- instead of a warning message you want to throw an error or you want forcefully to ask your developers to change the method.
Please check the code sample and the output. Make the below change in your attribute.
- [Obsolete("adition method logic is computed wrongly , now onwords please use improvised_adition",true)]

Summary
In this blog, we have discussed the importance of obsolete attribute and the method depreciation concept with a simple program.

Suhas C MPosted Aug 4, 2020, 12:12 PM
Super and very useful
ramlalPosted Jul 23, 2020, 2:00 PM
very useful
Guest UserPosted Jul 22, 2020, 7:51 AM
Awesome tip.
Rathrola Prem KumarPosted Jul 21, 2020, 8:50 PM
Usefull Info