Mark a class or method as deprecated in c#

Background

The attribute Obsolete is used to mark types and members of types that should no longer be used. the Obsolete attribute is found in the System namespace; which means you can specify the type as Obsolete or ObsoleteAttribute—the suffix “Attribute” is automatically added at compile-time. A class or function can be made deprecated in c# by using obsolete attribute.For class/function use this attribute at top of the class/function. You can call attribute constructor by two ways,

[System.Obsolete("WARNING_MESSAGE")]
[System.Obsolete("WARNING_MESSAGE",[show compiler error true|false])]

Below is the example that shows usage of both constructor,

[Obsolete("Method1 is deprecated, please use Method2 instead.")]
public string Method1()
{
//function body
}

Upon calling this function compiler wont produces warning or error.

[System.Obsolete("Class1 is deprecated, use class2"),true]
class Class1
{
public void Method() { //function body  }
}

Upon calling instantiating this class, compiler wont produces warning or error.