Q:

C# program to demonstrate the #if preprocessor directive

0

C# program to demonstrate the #if 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 #if preprocessor directive is given below. The given program is compiled and executed successfully on Microsoft Visual Studio.

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

#define MY_MACRO
using System;
using System.Diagnostics;

class Program
{
   public static void Main()
    {
        #if (MY_MACRO)
            Console.WriteLine("Macro is defined");
        #else
            Console.WriteLine("Macro is not defined");
        #endif
    }
}

Output:

Macro is defined
Press any key to continue . . .

Explanation:

In the above program, we defined a macro "MY_MACRO". Here we created a class Program that contains the Main() method. The Main() method is the entry point for the program. Here, we checked "MY_MACRO" is defined or not. In our program, we already defined the "MY_MACRO" that's why the "Macro is defined" message will be printed on the console screen.

 

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