The class implements the IDisposable interface, which means that it has a Dispose method.
Not every class that implements IDisposable requires a call to Dispose , but most do. If you see that the class implements IDisposable (or has the Dispose method, because it inherits the interface from the base class), you have two choices:
Any method is safe. If the Dispose method does nothing, the call will be very fast. You can even call Dispose more than once without harm.
Moreover, just calling the Dispose method is to use the using block:
using (FileStream s = File.OpenRead(path)) { ... }
At the end of a block bracket, the Dispose method is called automatically. The using block is implemented as try...finally , so the Dispose method is guaranteed to be called even if an exception is thrown in the block.
source share