Veikedo

[C# interview] disposable

Dec 7th, 2020
165
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.47 KB | None | 0 0
  1. // What will be the output?
  2.  
  3. using System;
  4.  
  5. class A : IDisposable
  6. {
  7.     public A()
  8.     {
  9.         throw new Exception("A::Exception");
  10.     }
  11.  
  12.     public void Do()
  13.     {
  14.         Console.WriteLine("A::Do()");
  15.     }
  16.  
  17.     public void Dispose()
  18.     {
  19.         Console.WriteLine("A::Dispose()");
  20.     }
  21. }
  22.  
  23. public class Program
  24. {
  25.     static void Main(string[] args)
  26.     {
  27.         try
  28.         {
  29.             using (var a = new A())
  30.             {
  31.                 a.Do();
  32.             }
  33.         }
  34.         catch (Exception e)
  35.         {
  36.             Console.WriteLine(e.Message);
  37.         }
  38.     }
  39. }
Add Comment
Please, Sign In to add comment