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

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Dynamics 365 Community / Blogs / mfp's two cents / X++ in AX7: Finally and using

X++ in AX7: Finally and using

Michael Fruergaard Pontoppidan Profile Picture Michael Fruergaard ... 1,616

Finally, X++ got support for the finally statement. It has exactly the same semantics as in C#. This means that you can now write: 

try 
{
}     
catch 
{
}      
finally 
{
}    

The contents of the finally block is guaranteed to be executed - regardless of exceptions or transactions. It is typically used to clean up any usage of none-managed resources. And to make that construct even cleaner, you can use the using keyword for types implementing the System.IDisposable interface.

using(var myObject = new MyObject()) 
{
    myObject.someMethod();  
}

  

This is short hand for:

var myObject = new MyObject();  
try 
{
    myObject.someMethod();  
} 
finally  
{
    myObject.Dispose();  
}  

One more thing…

Just like in C# the using statement can also be used to avoid providing fully qualified names when referencing .NET types. This means I can implement MyObject like this:

using System;  
class MyObject implements IDisposable   
{              
    public void Dispose()
    {
    }
}     


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

1134.AX7TShirt.jpg

Comments

*This post is locked for comments