About This eBook by Bart De Smet

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

O'Reilly logo

Implementing IDisposable

You haven’t seen how to declare a type or implement an interface just yet, but it is very simple to understand. To create an IDisposable type, you write something like this:

class MyResource : IDisposable /* this means we're implementing IDisposable */{    // Useful members go here.    public void Dispose()    {        // Do some disposal operation here.    }}

Things are a bit more complicated, though, because you usually want the underlying resources to get deallocated even if the Dispose method is not called (because of a type’s user screwing up, for example). This is where the use of a finalizer comes in, discussed in depth in Chapter 12, “Constructors and Finalizers.” To put it simply, ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required