Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- class D : IDisposable
- {
- void IDisposable.Dispose() { }
- }
- static class Program
- {
- static void Main() {
- var d = new D();
- // #1 Looks like typecast
- ((IDisposable)d).Dispose();
- // #2 Temporary variable w/o typecast
- IDisposable dd = d;
- dd.Dispose();
- // #3 - Calling extension
- d.Dispose();
- }
- static void Dispose<T>(this T instance) where T : IDisposable {
- if(instance == null) {
- throw new ArgumentNullException("instance");
- }//if
- instance.Dispose();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment