How do I mark a method as obsolete or deprecated using C#?
How do I mark a method as obsolete or deprecated using C#?
To mark as obsolete with a warning:
[Obsolete]
private static void SomeMethod()
You get a warning when you use it:

And with IntelliSense:

If you want a message:
[Obsolete("My message")]
private static void SomeMethod()
Here's the IntelliSense tool tip:

Finally if you want the usage to be flagged as an error:
[Obsolete("My message", true)]
private static void SomeMethod()
When used this is what you get:

Note: Use the message to tell people what they should use instead, not why it is obsolete.
With ObsoleteAttribute you can mark a method as deprecated.
It has three constructors:
[Obsolete]:is a no parameter constructor and is a default using this attribute.[Obsolete(string message)]:in this format you can getmessageof why this method is deprecated.[Obsolete(string message, bool error)]:in this format message is very explicit buterrormeans, in compilation time, compiler must be showing error and cause to fail compiling or not.
For dependency injected methods, Apply the [Obsolete("description")] attribute to the declaration rather than implementation (:doh: moment for me)