Skip to content

Instantly share code, notes, and snippets.

@dellis1972
Created March 10, 2012 23:28
Show Gist options
  • Save dellis1972/2013917 to your computer and use it in GitHub Desktop.
Save dellis1972/2013917 to your computer and use it in GitHub Desktop.
using System;
namespace UsingUsingBlocks
{
class SomethingThatDisposes : IDisposable
{
public SomethingThatDisposes()
{
Console.WriteLine("Creating");
}
#region IDisposable implementation
public void Dispose ()
{
Console.WriteLine("Disposing");
}
#endregion
}
class MainClass
{
public static void Main (string[] args)
{
try
{
using( SomethingThatDisposes std = new SomethingThatDisposes())
{
throw new InsufficientMemoryException("Ouch");
}
}
catch(Exception ex)
{
Console.WriteLine( "Exception : " + ex.Message);
}
finally
{
Console.ReadLine();
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment