How does the IDisposable interface work?

前端 未结 4 1733
谎友^
谎友^ 2021-01-17 20:01

I understand that it is used to deallocate unmanaged resources, however, I am confused as to when Dispose is actually called. I know it is called at the end of

4条回答
  •  不要未来只要你来
    2021-01-17 20:22

    No it does not get called when the object is garbage collected. If you want that behavior you can use the destructor (finalizer) and the call Dispose() from there.

    As you say it is automatically called and the end of a using block.

提交回复
热议问题