How to destroy an object in C#

This question already has an answer here:

  • Proper use of the IDisposable interface 18 answers

  • 除了将对象设置为null之外,还应该将其从其他对象中移除,如果您使用的资源需要释放,请使用IDisposable

    public class Car: IDisposable
    {
        // free resources
        public void Dispose()
        {
    
        }
    }
    

    set c = null; As long as there are no other references to it, the garbage collector will destroy it the next time it runs.

    链接地址: http://www.djcxy.com/p/54474.html

    上一篇: 这是如何“正确实施IDisposable”?

    下一篇: 如何在C#中销毁对象