Chris Ballance Chris Ballance - 3 months ago 15
C# Question

How do I mark a method as Obsolete/Deprecated?

How do I mark a method as Obsolete/Deprecated using C#?

Answer

The shortest way is adding a Method Attribute:

 [Obsolete]

You can add an explanation:

 [Obsolete("Method1 is deprecated, please use Method2 instead.")]

You can also cause the compilation to fail (treat method use as error instead of warning) if the method is called from somewhere in code like this:

 [Obsolete("Method1 is deprecated, please use Method2 instead.", true)]

(Thanks @rick)

Comments