ADVERTISEMENT
ADVERTISEMENT

C# program to demonstrate the #region preprocessor directive

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

Here, we will demonstrate the #region preprocessor directive. We can create a region in the code using the #region preprocessor directive. The #region directive is used to organize the code, it cannot overlap a #if directive.

Program:

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

//C# program to demonstrate the #region preprocessor directive.
using System;

class Program
{
   public static void Main()
   {
        Console.WriteLine("Before Region");
#region RegionCountries
	Console.WriteLine("\tIndia");
	Console.WriteLine("\tAustralia");
	Console.WriteLine("\tAmerica");
	Console.WriteLine("\tEngland");
#endregion
        Console.WriteLine("After Region");
   }
}

Output:

Before Region
        India
        Australia
        America
        England
After Region
Press any key to continue . . .

Explanation:

In the above program, we created a class Program that contains the Main() method. Here, we created a region that contains some statements using the #region preprocessor directive.

Using the #region preprocessor directive, we can create a region in the code using the #region preprocessor directive. The #region directive is used to organize the code, it cannot overlap a #if directive.

C# Basic Programs »


ADVERTISEMENT



ADVERTISEMENT



Comments and Discussions


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.