The source code to demonstrate the Obsolete attribute is given below. The given program is compiled and executed successfully on Microsoft Visual Studio.
//C# program to demonstrate the Obsolete attribute.
using System;
class Program
{
[Obsolete("Absoluted method")]
public static void SayHello()
{
Console.WriteLine("Hello World");
}
public static void Main()
{
SayHello();
}
}
Output:
Hello World
Press any key to continue . . .
Explanation:
In the above program, we created a class Program that contains two static methods, here we used the Obsolete attribute to specify the SayHello() method has been obsoleted and then called the method inside the Main() method.
The above code will generate a warning for the obsolete method and it will print "Hello World" on the console screen.
Program:
The source code to demonstrate the Obsolete attribute is given below. The given program is compiled and executed successfully on Microsoft Visual Studio.
Output:
Explanation:
In the above program, we created a class Program that contains two static methods, here we used the Obsolete attribute to specify the SayHello() method has been obsoleted and then called the method inside the Main() method.
The above code will generate a warning for the obsolete method and it will print "Hello World" on the console screen.