Region Directive in AL

APPLIES TO: Business Central 2020 release wave 2 and later


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're currently working on. The #endregion specifies the end of a #region block of code.


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


#region [comment]


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

A #region block can't 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.


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()
        // No one should look at this

See Also

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