Close and Dispose - which to call?

后端 未结 7 1211
慢半拍i
慢半拍i 2020-11-22 09:38

Having read the threads Is SqlCommand.Dispose enough? and Closing and Disposing a WCF Service I am wondering for classes such as SqlConnection or one of the several classes

7条回答
  •  时光说笑
    2020-11-22 10:00

    For SqlConnection, from the perspective of the connection itself, they are equivalent. According to Reflector, Dispose() calls Close() as well as doing a few additional memory-freeing operations -- mostly by setting members equal to null.

    For Stream, they actually are equivalent. Stream.Dispose() simply calls Close().

提交回复
热议问题