Skip to content

Instantly share code, notes, and snippets.

@CartBlanche
Created March 10, 2012 23:16
Show Gist options
  • Save CartBlanche/2013866 to your computer and use it in GitHub Desktop.
Save CartBlanche/2013866 to your computer and use it in GitHub Desktop.
Using Block example
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)
{
using( SomethingThatDisposes std = new SomethingThatDisposes())
{
try
{
throw new InsufficientMemoryException("Ouch");
}
catch (Exception ex)
{
Console.WriteLine( "Exception : " + ex.Message);
}
}
Console.ReadLine();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment