IDisposable not implemented in BinaryReader and BinaryWriter?

  • Thread starter Thread starter Brane Brodnik
  • Start date Start date
B

Brane Brodnik

Following code returns compile time error: "Cannot implicitly convert type
'System.IO.BinaryWriter' to 'System.IDisposable'" in CompactFramework. In
full Framework it works fine. Is there an explanation for that?

MemoryStream m = new MemoryStream();

using (BinaryWriter w = new BinaryWriter(m))

{

}

Thanks,

Brane Brodnik
 
well, that's life !
may object which used to be IDisposable are no longer in the framework.
although they still (sometimes) implement a Dispose() method :)

Anyway you could try the following peace of code, instead:

MemoryStream ms = new MemoryStream();
BinaryWriter w = null;
try
{
w = new BinaryWriter(ms);
// ....
}
finally { if(w != null) w.Close(); }


However in your case it doesn't really matter, I would guess that
BinaryWriter or MemoryStream use no native resources ...
 
Back
Top