How to replace this statement with try/finally block?
using(MemoryStream ms = new MemoryStream()){}
Is this the correct approach?
MemoryStream ms = new MemoryStream();
try
{
//code
}
finally
{
ms.Dispose();
}
How to replace this statement with try/finally block?
using(MemoryStream ms = new MemoryStream()){}
Is this the correct approach?
MemoryStream ms = new MemoryStream();
try
{
//code
}
finally
{
ms.Dispose();
}
It's rather like this:
MemoryStream ms = null;
try
{
ms = new MemoryStream();
//code
}
finally
{
if (ms != null) ms.Dispose();
}
The reason is that the mere instantiation may create disposable resources.