ADVERTISEMENT
ADVERTISEMENT

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 »


ADVERTISEMENT




ADVERTISEMENT


Comments and Discussions!

ADVERTISEMENT

ADVERTISEMENT

ADVERTISEMENT

ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT

Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.