using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
class MyResources : IDisposable
{
private bool disposed = false;
public void Dispose()
{
Dispose(true);
}
public void Close()
{
Dispose(true);
}
~MyResources()
{
Dispose(false);
}
private void Dispose(bool disposing)
{
if (!this.disposed)
{
if (disposing)
{
Console.WriteLine("调用所引用对象的Dispose()方法");
}
Console.WriteLine("释放类本身所使用的的非托管资源");
this.disposed = true;
if (disposing)
{
GC.SuppressFinalize(this);
}
}
}
}
class Program
{
static void Main(string[] args)
{
MyResources Mr = new MyResources();
try
{
Console.WriteLine("Mr做的事情");
}
finally
{
Mr.Dispose();
}
}
}
}
浙公网安备 33010602011771号