Advertisement
klippa

IDisposable

Aug 19th, 2022
758
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.45 KB | None | 0 0
  1. public class SomeClass: IDisposable
  2. {
  3.     private bool disposed = false;
  4.  
  5.     public void Dispose()
  6.     {
  7.         Dispose(true);
  8.         GC.SuppressFinalize(this);
  9.     }
  10.  
  11.     protected virtual void Dispose(bool disposing)
  12.     {
  13.         if (disposed) return;
  14.         if (disposing)
  15.         {
  16.             // Managed
  17.         }
  18.         // Unmanaged
  19.         disposed = true;
  20.     }
  21.  
  22.     ~SomeClass()
  23.     {
  24.         Dispose (false);
  25.     }
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement