Does the using statement dispose only the first variable it create?

后端 未结 6 918
猫巷女王i
猫巷女王i 2021-01-12 15:27

Let\'s say I have a disposable object MyDisposable whom take as a constructor parameter another disposable object.

using(MyDisposable myDisposab         


        
6条回答
  •  醉话见心
    2021-01-12 15:53

    You only initialized one disposable variable in the using statement. The AnotherDisposable nested object is created through normal initialization, not by using. So only the myDisposable variable you created with the using statement will automatically be disposed by it.

提交回复
热议问题