Is there a list of common object that implement IDisposable for the using statement?

前端 未结 9 2384
挽巷
挽巷 2020-12-17 15:10

I was wondering if there was some sort of cheat sheet for which objects go well with the using statement... SQLConnection, MemoryStream, etc.

9条回答
  •  眼角桃花
    2020-12-17 15:59

    A quick&dirty way of checking if a type implements IDisposable is to create an instance of it and check if the instance has a Dispose() member function. If it does then you can be 99% sure that it implements IDisposable.

提交回复
热议问题