Return an object created by USING

后端 未结 9 1497
南方客
南方客 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 06:01

    Yep, this will cause problems. If you have this case (I could think of a method returning a database accessor class) don't use a using block, as you aren't responseable for the disposal of this object, but the caller is.

提交回复
热议问题