web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :

How to use Ternary Operator (?) In X++

Rahul Kiran Profile Picture Rahul Kiran 481

Ternary Operator (?)  is one of code optimization technique in X++ .It acts as a IF condition in axapta

Syntax : 

expression1 ? expression2 : expression3
expression1 must be a Boolean expression. If expression1 is true, the whole ternary statement resolves to expression2; otherwise it resolves to expression3.
expression2 and expression3 must be of the same type as each other.
Example :
By using Ternary operator(?):
int nVar = 2;
;
print nVar < 3 ? nVar + 1 : nVar - 1; // print output 3.
pause;
Same Code By using If() Condition:
int nVar = 2;
;
if(nVar < 3)
{
  nVar = nVar +1;
}
else
{
nvar = nvar-1;
}
// print output 3.

Comments

*This post is locked for comments