标签:
1.接口的引用
static void Main(string[] args)
{
using (CaryClass caryClass = new CaryClass()) // IDisposeable接口用using来调用
{
caryClass.DoSomething();
}
CaryClass caryClass2 = new CaryClass();
try
{
caryClass2.DoSomething();
}
finally
// 用finally来实现借口的调用{
IDisposable disposable = caryClass2 as IDisposable;
if (disposable != null)
disposable.Dispose();
}
Console.ReadKey();
}
}
public class CaryClass : IDisposable
{
public void DoSomething()
{
Console.WriteLine("Do some thing....");
}
public void Dispose()
{
Console.WriteLine("及时释放资源");
}
}
标签:
原文地址:http://www.cnblogs.com/weloveshare/p/5294814.html