Q:

C# program to demonstrate the #pragma preprocessor directive

0

C# program to demonstrate the #pragma preprocessor directive

All Answers

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

Program:

The source code to demonstrate the #pragma preprocessor directive is given below. The given program is compiled and executed successfully on Microsoft Visual Studio.

//C# program to demonstrate the 
//#pragma preprocessor directive.

using System;

class Program
{
   public static void Main()
    {
        #pragma warning restore
        #warning First warning
        #pragma warning disable
        #warning Second warning
    }
}

Output:

Warning	1	#warning: 'First warning'

Explanation:

The above program will generate a warning because we can enable or disable warnings using the #pragma directive. We can disable warning using "#pragma disable" and warning can be enabled using the "#pragma restore" directive.

Here, we created a Program class that contains the Main() method. The Main() method is the entry point for the program, here we used the #pragma directive to disable and enable warnings.

 

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

total answers (1)

Similar questions


need a help?


find thousands of online teachers now