using (MyClass myClass = new MyClass())
{
myClass.DoSomething();
}
Compiler自動轉成:
using (MyClass myClass = new MyClass())
{
MyClass myClass = new MyClass();
try
{
myClass.DoSomething();
}
finally
{
IDisposable dis = myClass as IDisposable;
if (dis != null)
{
dis.Dispose();
}
}
有時候了解Compiler的真正運作方式,能幫助程序員更有信心決定使用時機。
原文: http://www.codeproject.com/KB/cs/using_and_IDisposable.aspx
No comments:
Post a Comment