static void PropertiesInUsingBlock() { try { using (var x = new ThrowingDisposable()) { x.Name = "In using block"; x.Bang = "Ouch"; } } catch (Exception) { Console.WriteLine("Caught exception"); } }
static void WithObjectInitializer() { try { using (var x = new ThrowingDisposable { Name = "Object initializer", Bang = "Ouch" }) { // Nothing } } catch (Exception) { Console.WriteLine("Caught exception"); } }