Considering that the BinaryWriter/BinaryReader object closes the underlaying
stream upon being gc collected, is the following code correct, and if it is
what is the reason preventing BinaryWriter object garbage collection after
the WriteSomething method is executed?
----
using System;
using System.IO;
namespace Test
{
class Test
{
static void Main(string[] args)
{
using (Stream output = (Stream)File.Op enWrite("test.t xt"))
{
WriteSomething( output);
WriteSomethingE lse(output);
}
}
static void WriteSomething( Stream outputStream)
{
BinaryWriter writer = new BinaryWriter(ou tputStream);
writer.Write("S omething");
}
static void WriteSomethingE lse(Stream outputStream)
{
BinaryWriter writer = new BinaryWriter(ou tputStream);
writer.Write("S omethingElse");
}
}
}
---
Comment