static void FuckWithIDisposable_using() { System.Console.WriteLine("=> fun with dispose:"); using (MySRCWrapper rw = new MySRCWrapper()) { // use rw object; } }
static void FuckWithIDisposable() { System.Console.WriteLine("=> fun with IDisposable:"); MySRCWrapper rw = new MySRCWrapper(); if (rw is IDisposable) { rw.Dispose(); } Console.ReadLine(); }
static void FuckWithIDisposable_try_finally() { System.Console.WriteLine("=> fun with dispose:"); MySRCWrapper rw = new MySRCWrapper(); try { // ...; } finally { // no matter error or not // always call Dispose() rw.Dispose(); } }