StreamReader class has both close and dispose method. I want to know which method to call to clean up all resources.
If making use of using block, I think it will c
We all know System.IO.StreamReader is not the only .NET 4.0+ class that implements IDisposable and a Close() method. For the case of StreamReader in this question, the source code shows that the base class TextReader.Close(), TextReader.Dispose() both run the same lines of code. You can also see in the code that TextReader.Dispose() is the implementation for when you call StreamReader.Dispose() (because StreamReader doesn't override that method overload signature of Dispose).
So a call to StreamReader.Dispose() will run this inherited line of code, which calls the protected override method StreamReader.Dispose(disposing: true) and so will StreamReader.Close() call StreamReader.Dispose(disposing: true). So for the case of StreamReader, Close() and Dispose() do happen to run the same lines of code.
A more general, non-class-specific answer to the question of Close() or Dispose()?, might be to note that Microsoft has fairly clear documentation on implementing IDisposable and the Dispose pattern. A quick read is enough to show you that implementing a Close() method is not a requirement of the Dispose pattern.
imho the reason for finding the method Close() on so many classes that implement IDisposable, is the result of convention, not requirement.
Someone commented
Close and Dispose - which to call?
An example of another class that implements IDisposable with the Dispose pattern, and has a Close() method. Does Close() run the same code as Dispose() in this case? I haven't looked at the source code, but I'd say not necessarily.