×

C# Tutorial

Basics of .Net

C# Basics

C# Fundamentals

C# Operators

C# Loops

C# Type Conversions

C# Exception Handling

C# String Class

C# Arrays

C# List

C# Stack

C# Queue

C# Collections

C# Character Class

C# Class and Object

C# Namespaces

C# Delegates

C# Constructors

C# Inheritance

C# Operator Overloading

C# Structures

C# File Handling

C# Convert.ToInt32()

C# Int32 (int) Struct

C# DateTime Class

C# Uri Class

C# Database Connectivity

C# Windows

C# Other Topics

C# Q & A

C# Programs

C# Find O/P

C# - #region Preprocessor Directive Example

Learn about the #region preprocessor directive example in C# with the help of example.
Submitted by Nidhi, on October 31, 2020 [Last updated : March 23, 2023]

Here, we will demonstrate the example of #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# program to demonstrate the example of #region preprocessor directive

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# - #region Preprocessor Directive Example.
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!

Load comments ↻


Advertisement
Advertisement
Advertisement

Copyright © 2025 www.includehelp.com. All rights reserved.