C-Sharp | Java | Python | Swift | GO | WPF | Ruby | Scala | F# | JavaScript | SQL | PHP | Angular | HTML
Tip: To specify an attribute, decorate a method with the declaration and surround the attribute with square brackets.
Info: You can use the Obsolete attribute with zero, one, and two arguments. This example uses one argument. It generates a compile-time warning.
C# program that uses Obsolete attribute
using System;
class Program
{
static void Main()
{
MethodA();
}
[Obsolete("Use MethodB instead")]
static void MethodA()
{
}
}
Output
... warning CS0618: 'Program.MethodA()' is obsolete: 'Use MethodB instead'
Finally: It can instead have two arguments. The compilation fails if you specify true as the second argument.
And: In larger projects this can help coordinate the methods different programmers employ.