Do we need to close a C# BinaryWriter or BinaryReader in a using block?

c#, idisposable, using

Solution

So long as it's all wrapped up in a `using` block then you don't need to explicitly call `Close`.

The `using` block will ensure that the object is disposed, and the `Close` and `Dispose` methods are interchangeable on `BinaryWriter`. (The `Close` method just calls `Dispose` behind the scenes.)

Problem

Having this code: ``` using (BinaryWriter writer = new BinaryWriter(File.Open(ProjectPath, FileMode.Create))) { //save something here } ``` Do we need to close the BinaryWriter? If not, why?

Original source

Related problems