Ternary operator in X++ Programming Language
Table of Content:
Ternary operator in X++ Programming Language
A ternary operator allows you to evaluate if an expression is true or false to get a result. This is like an if
statement, which is discussed in the Use conditional and iterative statements and Exception handling units. However, where an if
statement provides conditional branching for the code that is being run, the ternary operator result can be assigned to a variable. The following example checks if the variable x is equal to 5. If it is equal to 5, then the ternary operator assigns the value Yes to the result variable. If x does not equal 5, the ternary operator assigns the value No to the result variable.
result = (x==5) ? "Yes" : "No";