Created
March 10, 2012 23:28
-
-
Save dellis1972/2013917 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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