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
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.
Related Posts:
- Apply for C# Internship
- Practice MCA MCQs
- Practice Computer Science MCQs
- Check MCA Books
- Apply for Computer Science Internship