MethodA shows an Warning when called and MethodB is not an Obsolete Method
This is a C# Program to create obsolete class.
This C# Program Creates Obsolete Class.
Here the Obsolete attribute generates a compile-time warning. When a method has the Obsolete attribute, the C# compiler issues a warning if it is called.
Here is source code of the C# Program to Create Obsolete Class. The C# program is successfully compiled and executed with Microsoft Visual Studio. The program output is also shown below.
/* * C# Program to Create Obsolete Class */ using System; class Program { static void Main() { MethodA(); MethodB(); Console.Read(); } [Obsolete("Use MethodB Instead")] static void MethodA() { } static void MethodB() { Console.WriteLine(" MethodA shows an Warning when called and "+ "MethodB is not an Obsolete Method "); } }
In this C# program, we are creating two static methods methodA and methodB to use obsolete class. Hence the obsolete attribute generates a compile-time warning. When a method has the obsolete attribute, the C# compiler issues a warning if it is called.
MethodA shows an Warning when called and MethodB is not an Obsolete Method