snippetcsharpCritical
How to mark a method as obsolete or deprecated?
Viewed 0 times
howmarkmethoddeprecatedobsolete
Problem
How do I mark a method as obsolete or deprecated using C#?
Solution
The shortest way is by adding the
You can also cause the compilation to fail, treating the usage of the method as an error instead of warning, if the method is called from somewhere in code like this:
ObsoleteAttribute as an attribute to the method. Make sure to include an appropriate explanation:[Obsolete("Method1 is deprecated, please use Method2 instead.")]
public void Method1()
{ … }You can also cause the compilation to fail, treating the usage of the method as an error instead of warning, if the method is called from somewhere in code like this:
[Obsolete("Method1 is deprecated, please use Method2 instead.", true)]Code Snippets
[Obsolete("Method1 is deprecated, please use Method2 instead.")]
public void Method1()
{ … }[Obsolete("Method1 is deprecated, please use Method2 instead.", true)]Context
Stack Overflow Q#1759352, score: 2087
Revisions (0)
No revisions yet.