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.
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.
Output:
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.