Q:

C# program to create an obsolete method in a class

0

C# program to create an obsolete method in a class

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

Program:

The source code to create an obsolete method in a C# class is given below. The given program is compiled and executed successfully on Microsoft Visual Studio.

//C# Program to create an Obsolete method in a class
using System;

class Sample
{
    [Obsolete("Use Display() method")]
    static void Print()
    {
    }
    
    static void Display()
    {
        Console.WriteLine("Print() method is obsolete, Use Display method in place of Print() method");
    }

    static void Main()
    {
        Print();
        Display();
    }
}

Output:

Print() method is obsolete, Use Display method in place of Print() method
Press any key to continue . . .

Explanation:

In the above program, we created a Sample class that contains three methods Print()Display(), and Main().

Here we used the Obsolete attribute to obsolete a method with a specified warning message. Then we called both Print() and Display() method in the Main() method.

 

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

C# Basic Programs | Class, Object, Methods

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now
C# program to demonstrate the example of Pass by r... >>
<< C# program to demonstrate the example of anonymous...