Scope of Variables in Methods

Applies To: Microsoft Dynamics AX 2012 R3, Microsoft Dynamics AX 2012 R2, Microsoft Dynamics AX 2012 Feature Pack, Microsoft Dynamics AX 2012

A scope defines the area in which an item can be accessed. Variables defined in a class are available to the methods within that class. Variables in methods can be accessed only within the current block, as shown in the following figure.

class variables

The class A contains methods b and c and class variables. All methods in the class can see and use all variables in the class.

The method b has some local variables that can only be accessed from within method b.

Method c has some local variables, a function d, and a function e. Functions d and e can be seen only inside method c. As functions d and e are declared inside method c, they have access to their local variables—the local variables in c and the variables in the class, respectively.

See also

Parameters and Scoping

Variable Scopes

Announcements: New book: "Inside Microsoft Dynamics AX 2012 R3" now available. Get your copy at the MS Press Store.