Partager via


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

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++.

Warning

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.

Sample of Static and Instance Method Calls into .NET

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
    *****/
    }

See also

.NET Interop from X++

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