Who Disposes of an IDisposable public property?

前端 未结 10 1653
萌比男神i
萌比男神i 2020-12-03 09:59

If I have a SomeDisposableObject class which implements IDisposable:

class SomeDisposableObject : IDisposable
{
    public void Dis         


        
10条回答
  •  南笙
    南笙 (楼主)
    2020-12-03 10:34

    An interesting thing that I've encountered is that SqlCommand owns an SqlConnection (both implement IDisposable) instance usually. However calling dispose on the SqlCommand will NOT dispose the connection too.

    I've discovered this also with the help of Stackoverflow right here.

    So in other words it matters if the "child" (nested?) instance can/will be reused later.

提交回复
热议问题