C# program to demonstrate the #undef preprocessor directive

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

Here, we will undefine the defined macro using the #undef pre-processor directive.


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

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

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

using System;

class Program
   public static void Main()
        #if (MACRO1)
            Console.WriteLine("MACRO1 is defined");
        #if (MACRO2)
            Console.WriteLine("MACRO2 is defined");
        #if (MACRO3)
            Console.WriteLine("MACRO3 is defined");


MACRO1 is defined
MACRO3 is defined
Press any key to continue . . .


In the above program, we defined three macros MACRO1, MACRO2, and MACRO3. After that, we undefined the MACRO2 using the #undef pre-processor directive.

Here, we created a class Program that contains the Main() method. The Main() method is the entry point for the program. Here we checked macros are defined or not and print the appropriate message on the console screen.

C# Basic Programs »


What's New (MCQs)

Comments and Discussions!

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.