46.
Assuming you have created a Class in your system. Which is an appropriate way of notifying the class that the object is going out of scope?
View Description
The following sample shows how a user-defined class can implement its own Dispose behavior. Note that your type must inherit from IDisposable
.
using System; class C : IDisposable { public void UseLimitedResource() { Console.WriteLine("Using limited resource..."); } void IDisposable.Dispose() { Console.WriteLine("Disposing limited resource."); } } class Program { static void Main() { using (C c = new C()) { c.UseLimitedResource(); } Console.WriteLine("Now outside using statement."); Console.ReadLine(); } }