X++ to C# Comparisons
Differences
The following table lists X++ features that are different in C#.
| Feature | X++ | C# | Comments |
|---|---|---|---|
| Declarations | All 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 statements | The 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 string | A literal string can be delimited by either of the following:
| 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 type | There 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 messages | X++ delivers messages to the user in the Infolog window. Common methods include the following:
| For a command line C# program, messages can be delivered to the console. Common methods include the following:
| 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
Post a Comment