daily pastebin goal
61%
SHARE
TWEET

Untitled

a guest Jul 20th, 2018 58 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. if( whatever is IDisposable) {
  2.   (whatever as IDisposable).Dispose();
  3. }
  4.    
  5. if( whatever is IDisposable) { //check
  6.   ((IDisposable)whatever).Dispose(); //cast - won't fail
  7. }
  8.    
  9. IDisposable whateverDisposable = whatever as IDisposable;
  10. if( whateverDisposable != null ) {
  11.    whateverDisposable.Dispose();
  12. }
  13.    
  14. if(whatever is IDisposable)  //check
  15. {
  16.   ((IDisposable)whatever).Dispose(); //cast - won't fail
  17. }
  18.    
  19. if(whatever is IDisposable)
  20. {
  21.   (whatever as IDisposable).Dispose();
  22. }
  23.    
  24. IDisposable whateverDisposable = whatever as IDisposable;
  25. if(whateverDisposable != null )
  26. {
  27.     whateverDisposable.Dispose();
  28. }
  29.    
  30. if (whatever is IDisposable) { //check
  31.     // <-- here, some other thread changes the value of whatever
  32.     ((IDisposable)whatever).Dispose(); // could fail
  33. }
  34.    
  35. IDisposable whateverDisposable = whatever as IDisposable;
  36. if( whateverDisposable != null)
  37. {
  38.    whateverDisposable.Dispose();
  39. }
  40.    
  41. public static void DisposeIfNecessary(this object obj)
  42. {
  43.    if (obj != null && obj is IDisposable)
  44.       ((IDisposable)obj).Dispose();
  45. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top