Thursday, June 21, 2012

Working with System.Char in X++

There are situations where it is useful to workl with characters in X++. As you know, X++ does not have the concept of characters in the defined in the language: Only strings are defined. However, it is not impossible to work with characters in X++, if you use the managed System.Char type. It will not win any prizes for elegance, but it works...

Consider the following example:

static void CharArray(Args _args)
{
    System.Char[] chars;
    System.Char a, b;

    a = System.Char::Parse('a');
    b = System.Char::Parse('b');
    chars = new System.Char[2]();
    chars.SetValue(a, 0);
    chars.SetValue(b, 1);
}

Here an array containing to chars is created, and assigned the values {'a', 'b'}. Note the special trick used to create a character literal, using the System.Char::Parse method.

No comments:

How to identify the user that was used to change an object from AOT in AX2012

Get the object name for which we need to track these (user and date&time) information's. Login to SQL Server Management Studio an...