Thursday, 23 October 2014

Ternary Operator (?) In Axapta 2012

Ternary Operator (?)  is one of code optimization technique in axapta .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.

No comments:

Post a Comment

Adding a newline into a string in C# and X++

Below is the sample code we can use for  adding a newline after every occurrence of "@" symbol in the string in C#   using System...