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.

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

Sanfoundry Global Education & Learning Series – 1000 C# Programs.

If you wish to look at all C# Programming examples, go to 1000 C# Programs.

If you find any mistake above, kindly email to [email protected]

advertisement
advertisement
Subscribe to our Newsletters (Subject-wise). Participate in the Sanfoundry Certification contest to get free Certificate of Merit. Join our social networks below and stay updated with latest contests, videos, internships and jobs!

Youtube | Telegram | LinkedIn | Instagram | Facebook | Twitter | Pinterest
Manish Bhojasia - Founder & CTO at Sanfoundry
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He lives in Bangalore, and focuses on development of Linux Kernel, SAN Technologies, Advanced C, Data Structures & Alogrithms. Stay connected with him at LinkedIn.

Subscribe to his free Masterclasses at Youtube & discussions at Telegram SanfoundryClasses.