What is the point of streamwriters having Close() and Dispose()?

.net, c#, com, vb.net, visual-c++

Solution

When dealing with streams there's a long standing convention that `Close` is a method that they have to close the stream. It's terminology that many programmers are used to and expect to see when dealing with streams. It would have been potentially confusing to have a stream without a `Close` method, and may have taken some time for people to realize that they should use `Dispose` to close the stream.

It's certainly possible for the class to have implemented `IDisposable` explicitly, so that the `Dispose` method wouldn't be there without a cast to `IDisposable`, and that my have cleaned up some of the confusion, but they choose not to do that and to leave two duplicate methods in the class.

It's entirely up to your personal preference whether you use `Dispose` or `Close` to close the stream.

Problem

When you call `Close` on an active `StreamWriter` it makes it impossible to write any more code to the stream (since it's been closed). To open another stream, you have to make a new instance of a `StreamWriter` since there's no 'Open' method. My question is, what's the point in having `Close` and `Dispose` when you can't really use anything besides `Dispose` after closing the stream? I could understand if there was an `Open` function, i.e. you could close one file then open another using the same `StreamWriter`. But as there is only `Close` and you can't really use anything besides `Dispose` afterwards, why not just get rid of `Close` and have `Dispose` close the underlying stream as its first action? I get that `Dispose` comes from `IDisposeable` and all that. What I want to know is why `Close` is needed specifically when `Dispose` appears to call `Close` anyway. As far as I can see, without the ability to open another stream with the same `StreamWriter`, there is no point in having `Close` when you have no option but to `Dispose` afterwards since all other methods become useless. Why is is that `StreamWriter` bothers having `Close` when they could merge `Close` and `Dispose` into a single method?

Original source