The Using Statement

The Using statement is used to get a resource, execute a nested statement block and then release the resource.

The structure or class implementing the System.IDisposable interface is named a resource. This interface has a single Dispose method that is used to release resource. The Using statement calls the Dispose method and releases resource after finishing the statement block located between the Using and End Using keywords.

A resource must be initialized between the Using and Do keywords. It is not recommended to initialize object before the Using statement, then pass it to the Using Do block and use after the End Using keywords because the object is not longer accessible. An attempt to use the object outside the Using block may throw an exception.

Example

Private Sub TestUsing();
Var
    newFont: System.Drawing.Font;
Begin
    
Using newFont := New System.Drawing.Font("Arial"10Do
        
//Use obtained font
    End Using;
End Sub;

See also:

Fore.NET Language Guide