Region Directive in AL

APPLIES TO: Business Central 2020 release wave 2 and later

Region

The #region directive is used to mark a block of code that you can expand or collapse. This can, for example, be useful for larger files for better readability or for focusing on code that you are currently working on. The #endregion specifies the end of a #region block of code.

Note

On the first line of the #region a text comment can be added to describe the purpose of the block of code, see the example below.

Syntax

#region [comment]
    code
#endregion

Remarks

A #region block must be terminated with a #endregion directive.

A #region block cannot overlap with an #if block. However, a #region block can be nested in an #if block, and an #if block can be nested in a #region block.

Example

In this example the #region directive makes a code block that is up for refactoring collapsible.

#region Ugly code - let's not look at this
    procedure UglyCode()
    begin
        // No one should look at this
    end;
#endregion

See Also

Development in AL
AL Development Environment
Pragma Directive in AL
Conditional directives
Deprecating Explicit and Implicit With Statements