The this Object

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

In an X++ method, the keyword this is a reference to the instance of the class or table in which the this keyword is used. The this reference is never required, but it can clarify your code, and it enhances the behavior of IntelliSense in the code editor.

The this reference can be used in the following ways:

  • Can be used to qualify the names of other instance (non-static) methods in the same class where the this reference is used. For example:
     boolColorChanged = this.colorItOrange();

    Note

    In X++ all calls to instance methods must be qualified, either with the this reference or with a variable.
    In contrast, C# does not always require such qualification.

  • Can be used to quality the names of methods that are inherited by the this object.

  • Can be used to qualify the names of fields on the table that contains the method that the this keyword is used in.

The this reference cannot be used in the following ways:

  • Cannot be used to qualify the names of member variables that are declared in the classDeclaration code.
    C# allows such qualification.

  • Cannot be used in a static method.

  • Cannot be used to qualify the names of static methods of the class or table.

See also

Methods in X++

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