Home »
.Net »
C# Programs
C# program to demonstrate the Obsolete attribute
Here, we are going to demonstrate the Obsolete attribute in C#?
Submitted by Nidhi, on October 31, 2020
Here, we will demonstrate the Obsolete attribute. The Obsolete attribute is used to specify the method has been obsoleted.
Program:
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.
C# Basic Programs »