ADVERTISEMENT

ADVERTISEMENT

ADVERTISEMENT

C# program to demonstrate the #pragma preprocessor directive

Here, we are going to demonstrate the #pragma preprocessor directive in C#?
Submitted by Nidhi, on October 31, 2020

Here, we will demonstrate the #pragma preprocessor directive. 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.

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.

C# Basic Programs »


ADVERTISEMENT



ADVERTISEMENT



Comments and Discussions

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.