static void Main() { // TODO: Implement the "using" block to do the // following: // 1. Declare and create an instance of a CheckingAccount // passing in the message // "Dispose method is called automatically.". // 2. Display the message on the Console that the CheckingAccount // instance is being processed in a using block. using (CheckingAccount ca = new CheckingAccount("Dispose method is called automatically.")) { Console.WriteLine("CheckingAccount instance is being processed in a using block"); } //TODO: Create a separate instance of the CheckingAccount outside of a // "using" block passing in the message // "Dispose method is being called explicitly.". CheckingAccount ca2 = new CheckingAccount("Dispose method is being called explicitly."); //TODO: Call the Dispose method of the just created instance of the // CheckingAccount. ca2.Dispose(); Console.Write("\n\nPress <ENTER> to end: "); Console.ReadLine(); }
static void Main() { using (CheckingAccount ca1 = new CheckingAccount("Dispose method is called automatically.")) { Console.WriteLine("Destructor will not run as Dispose method will be called automatically."); } CheckingAccount ca2 = new CheckingAccount("Dispose method is not called causing the Destructor to run."); Console.Write("\n\nPress <ENTER> to end: "); Console.ReadLine(); }