X++ to C# Comparisons

Differences

The following table lists X++ features that are different in C#.
FeatureX++C#Comments
DeclarationsAll declarations must be at the start of the method, before any X++ statements.Declarations can occur anywhere in the method.Both languages permit multiple variables of the same type to be listed together in one declaration. Both languages allow you to assign an initial value in the declaration statement.
if and elseconditional statementsThe if statement accepts any type of expression that it can automatically convert to a Boolean. Common examples include an int for which 0 means false, or an object for which null means false.The if statement requires a Boolean expression.The syntax structure regarding curly braces and parentheses is exactly the same between X++ and C#.
Literal stringA literal string can be delimited by either of the following:
  • A pair of double quotation mark (") characters.
  • A pair of single quotation mark (') characters.
A literal string must be delimited by a pair of double quotation mark (") characters.For X++, the double quotation mark characters are usually used to delimit strings. However, it is convenient delimit a string with single quotation mark characters when your string must contain a double quotation mark character.
char typeThere is no char or character type in X++. You can declare a strof length one, but it is still a string:
str 1 myString = "a";
There is a char in C#. You cannot pass a char as the parameter to a method that inputs a stringparameter, although you can first explicitly convert the char to a string.For more information about X++ data types, see Primitive Data Types.
Output of messagesX++ delivers messages to the user in the Infolog window. Common methods include the following:
  • The printstatement:
  • static methods on the Globalclass:
    • Global::info
    • Global::warning
    • Global::error
For a command line C# program, messages can be delivered to the console. Common methods include the following:
  • Console.Out.WriteLine
  • Console.Error.WriteLine
The print statement is not a function nor a method. Recommended use would be print mystring;rather than print(mystring);. A pause;statement is always useful shortly after a print statement. The print statement is convenient for testing because it automatically converts int and other primitive values to strings for display. For more information, see Print Statements. The Global class has special recognition in the X++ compiler. The info method can be called without including the Global:: prefix.

Comments

Popular posts from this blog

How to import data in Ax2009 from a CSV file

July 2017 update: Form Adaptors Replaced by Type Providers