redSkywalker

tests2

Mar 8th, 2018
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.94 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace tests1
  8. {
  9.  
  10.     class Program
  11.     {
  12.         static void Main(string[] args)
  13.         {
  14.             var s = new S(); //здесь все в порядке
  15.             using (s)
  16.             {
  17.                
  18.                 Console.WriteLine(s.GetDispose());
  19.             }
  20.             Console.WriteLine(s.GetDispose());//и здесь все в порядке
  21.             Console.ReadKey();
  22.         }
  23.     }
  24.     public struct S : IDisposable
  25.     {
  26.         private bool dispose;  //значение bool по умолчанию равно false. А метод Dispose не вызывается. Поэтому вывод: false, false
  27.         public void Dispose()
  28.         {
  29.             dispose = true;
  30.         }
  31.         public bool GetDispose()
  32.         {
  33.             return dispose;
  34.         }
  35.     }
  36. }
Advertisement
Add Comment
Please, Sign In to add comment