With my previous post about Instantiating Managed Objects with C++/CLI you could read about using ref types two different ways: with local variables and with a handle.
Now I'm adding implementing the IDisposable interface with the Test class:
ref class Test
With C++/CLI the IDisposable interface is implemented with the destructor syntax.
Now it would be good to do a try/finally to dispose the object. With C++/CLI the object is disposed using delete.
Test^ t = gcnew Test();
With local variables the same can be done with fewer lines of code. This is shorter than the C# using statement!
The generated code is nearly the same. Nearly as in the first version the IL code uses the IL .try/finally statements, whereas the second version uses IL .try/fault and disposes the object in the fault and the default case.