X++ in AX7: Inline variable declarations


What would you pay to be able to do this in X++?

for (int i = 1; i <= n; i++)   
{
}    

Or this:

if (i > 0)    
{
    int positiveInt = i;  
}  

Or this:

if (applyInterestRate)
{
    real rate = this.getInterestRate();  
    result = result * rate;  
}  
if (applyExchangeRate) 
{  
    ExchangeRate rate = this.getExchangeRate();  
    result = result * rate.ExchangeRate;  
}  

Finally, we can:

  • Declare variables close(r) to where they are used,
  • Variables are scoped by the block in which they are declared, and
  • Variable names can be reused in another scope.

The price: Join the ranks of AX7 developers!

Note: Whenever you consider using inline variable declarations – consider extracting the code into a smaller method instead. Here is why.

 

THIS POST APPLIES TO MICROSOFT DYNAMICS AX7 TECHNICAL PREVIEW; IS PROVIDED AS-IS AND CONFERS NO RIGHTS.

Comments (0)

Skip to main content