How to: Access Static and Instance Members of .NET Framework Classes from X++ [AX 2012]

Updated: May 11, 2011

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

In Microsoft Dynamics AX, the X++ syntax for calling .NET Framework methods is different for calling static methods than it is for calling instance methods. In both cases, the dot character (.) is used to delimit all the namespaces of the fully qualified type name. However, for calling static .NET Framework methods, you must use a double colon (::) between the class name and the method name. This is consistent with the double colon that you use when you call static methods that are written in X++.

Caution noteCaution

Starting in Microsoft Dynamics AX 2012 you rarely need to include a semicolon before the first statement in your X++ methods. However, you need the semi-colon in X++ methods that call static methods in the .NET Framework.

In the following X++ code sample, the static and instance method calls are as follows:

  • Static: System.Convert::ToString

  • Instance: netString.Substring

static void JobStaticInstanceSyntax95(Args _args)
{
    System.Int32 netInt;
    System.String netString;
    str xppString;
    ;
    netInt = 123456;

    // static
    netString = System.Convert::ToString(netInt);

    // instance
    netString = netString.Substring(3,2);

    xppString = netString;
    info(xppString);

/***** Actual infolog output
Message (05:58:20 am)
45
*****/
}

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

Community Additions

ADD
Show: