ADVERTISEMENT
ADVERTISEMENT

C# program to demonstrate the #error preprocessor directive

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

Here, we will use the #error directive then the program will generate a syntax error.

Program:

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

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

#define MACRO1
#define MACRO2
#define MACRO3
#undef  MACRO2

using System;

class Program
{
   public static void Main()
   {
        #if (!MACRO2)
            #error MACRO2 is not defined
        #endif
    }
}

Output:

Error	1	#error: 'MACRO2 is not defined'	

Explanation:

The above program will generate a syntax error because here we used the #error directive with an error message in the Main() method then the specified message will print as a syntax error when we compile the program.

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.