C# conditional using block statement

后端 未结 10 1700
佛祖请我去吃肉
佛祖请我去吃肉 2021-02-02 07:25

I have the follow code but it is awkward. How could I better structure it? Do I have to make my consuming class implement IDisposable and conditionally construct the network acc

10条回答
  •  南笙
    南笙 (楼主)
    2021-02-02 08:12

    Whatever is enclosed within the using statement will have it's IDispoable.Dispose called as dictated by the IDisposable interface. As seen on MSDN for using...

    Provides a convenient syntax that ensures the correct use of IDisposable objects.

    Therefore if you put a custom type within the using statement it should clean up its resources appropriately via the IDisposable interface.

提交回复
热议问题