将 using 语句替换为等于 try/finally 块

Replace using statement with equal try/finally block

如何用 try/finally 块替换此语句?

using(MemoryStream ms = new MemoryStream()){}

这是正确的方法吗?

MemoryStream ms = new MemoryStream();
try
{
   //code
}
finally
{
   ms.Dispose();                
}

大概是这样的:

MemoryStream ms = null;
try
{
   ms = new MemoryStream();

   //code
}
finally
{
   if (ms != null) ms.Dispose();                
}

原因是仅仅实例化可能会创建一次性资源。