日期:2014-05-17  浏览次数:20848 次

C#是不是同时有IDispose和IDisposable这两个接口?
本帖最后由 u011309590 于 2013-07-07 13:28:33 编辑
我下面的代码编译有错:


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace TestIDispose
{
    public class Program : System.IDisposable
    {
        public override void Dispose()
        {
            Dispose(true);
            //GC.SuppressFinalize(this);
            GC.Collect();
        }

        void Dispose(bool disposing)
        {
        }

        ~Program()
        {
            Dispose();
        }

        static void Main(string[] args)
        {
        }
    }
}


错误提示:
------ Build started: Project: TestIDispose, Configuration: Debug x86 ------
D:\Work\my\TestIDispose\Program.cs(10,30): error CS0115: 'TestIDispose.Program.Dispose()': no suitable method found to override

Compile complete -- 1 errors, 0 warnings
C:\WINDOWS\Microsoft.NET\Framework\v4.0.30319\Csc.exe /noconfig /nowarn:1701,1702 /nostdlib+ /platform:x86 /errorreport:prompt /warn:4 /define:DEBUG;TRACE /reference:"C:\Program Files\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0\Profile\Client\Microsoft.CSharp.dll" /reference:"C:\Program Files\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0\Profile\Client\mscorlib.dll" /reference:"C:\Program Files\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0\Profile\Client\System.Core.dll" /reference:"C:\Program Files\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0\Profile\Client\System.Data.DataSetExtensions.dll" /reference:"C:\Program Files\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0\Profile\Client\System.Data.dll" /reference:"C:\Program Files\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0\Profile\Client\System.dll" /reference:"C:\Program Files\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0\Profile\Client\System.Xml.dll" /reference:"C:\Program Files\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0\Profile\Client\System.Xml.Linq.dll" /debug+ /debug:full /filealign:512 /optimize- /out:obj\x86\Debug\TestIDispose.exe /target:exe Program.cs Properties\AssemblyInfo.cs "C:\Documents and Settings\U0138848\Local Settings\Temp\.NETFramework,Version=v4.0,Profile=Client.AssemblyAttributes.cs"