C# Program to Create Obsolete Class
Posted by Superadmin on August 14 2022 04:01:55

C# Program to Create Obsolete Class

 

 

 

This is a C# Program to create obsolete class.

Problem Description

This C# Program Creates Obsolete Class.

Problem Solution

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.

Program/Source Code

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 ");
    }
}
Program Explanation

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.

 
Runtime Test Cases
 
MethodA shows an Warning when called and MethodB is not an Obsolete Method