Developer, Former MVP, now at Microsoft - Best of 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013
class SomeType : IDisposable{ public SomeType(){ // do some ctor stuff } public void DoSomething(){ // do some useful stuff } public void Dispose(){ // clean up unmanaged resources }}
SomeType st = new SomeType();try{ st.DoSomething();}finally{ st.Dispose();}
using (SomeType st = new SomeType()){ st.DoSomething();}
using