Q:

C# program to demonstrate the use of #define preprocessor

0

C# program to demonstrate the use of #define preprocessor

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 use of #define preprocessor is given below. The given program is compiled and executed successfully on Microsoft Visual Studio.

//C# program to demonstrate the use of #define preprocessor

#define PRINT_MSG_TYPE1

using System;
class Program
{
    static void Main()
    {
        #if PRINT_MSG_TYPE1
            Console.WriteLine("Print message type1 on console screen");
        #endif

        #if PRINT_MSG_TYPE2
            Console.WriteLine("Print message type2 on console screen");
        #endif
    }
}

Output:

Print message type1 on console screen
Press any key to continue . . .

Explanation:

In the above program, we demonstrate the use of #define macro. Here we defined a macro PRINT_MSG_TYPE1 at the top in our program. Then we checked defined macros in the Main() method. Here we defined PRINT_MSG_TYPE1 macro but we did not define PRINT_MSG_TYPE2 macro that's why the message "Print message type1 on console screen" is printed.

 

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

total answers (1)

C# Basic Programs | Class, Object, Methods

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now
C# program to demonstrate the example of regular e... >>
<< C# program to create a user defined the namespace...