C# 什么对象需要Dispose()或Close()

68 阅读1分钟

什么对象需要使用using或者Dispose()或Close()手动合适的释放。

答:实现了IDisposable的类(要是能GC自动垃圾回收掉,为啥还要实现Dispose)

    //     Provides a mechanism for releasing unmanaged resources.
    public interface IDisposable
    {
        //
        // 摘要:
        //     Performs application-defined tasks associated with freeing, releasing, or resetting
        //     unmanaged resources.
        void Dispose();
    }