C# program to demonstrate the use of #define preprocessor

Here, we are going to learn about the #define preprocessor and its C# implementation.
Submitted by Nidhi, on September 11, 2020

Here we will demonstrate the use of #define preprocessors in the C# program, here we will check defined macros to display messages on the console screen.


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


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

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


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


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.

C# Basic Programs »


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.