C# #region directive

In this chapter you will learn:

  1. How to use #region directive
  2. Syntax for #region directive
  3. Example for #region directive

Using #region directive

The #region and #endregion directives define a region that will be expanded or collapsed when using outlining in the Visual Studio IDE.

Syntax

The general form is shown here:


#region region-name 
 // code sequence
#endregion

Example

The following code shows how to use #region and #endregion.


using System;/*  w  ww.  ja v a2s  . co  m*/

class MainClass
{
  [STAThread]
  static void Main(string[] args)
  {
      #region Stuff 
          
    
      #endregion

  }

}

The code above generates the following result.

Next chapter...

What you will learn in the next chapter:

  1. #warning directive produces a warning
  2. Syntax for #warning preprocessor
  3. Example for #warning preprocessor
  4. Unused Warning With Warning Suppressed
Home »
  C# Tutorial »
    C# Types »
      C# Preprocessor
C# preprocessor
C# #define Preprocessor
C# #if Preprocessing Directive
C# #elif Preprocessing Directive
C# #undef
C# #line directive
C# #region directive
C# #warning preprocessor