Return an object created by USING

后端 未结 9 1679
南方客
南方客 2021-01-18 05:32

I am creating an object(obj below) in using and return that object as part of the function return.Will this cause any problem like object will be disposed before I try to us

9条回答
  •  庸人自扰
    2021-01-18 05:37

    Your object will have disposed called on it right after you return it. It's still technically useable as it has not been garbage collected, but it will have the Dispose function ran.

    The rule I follow in this instance is that the method receiving the object is charged with disposing it. You don't know when that method is going to be finished with it, so it is that method's responsibility to tidy up after itself when it is done.

提交回复
热议问题