Return an object created by USING

后端 未结 9 1663
南方客
南方客 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:39

    Will this cause any problem like object will be disposed before I try to use returned value in another function?

    Yes.

    Can you explain what you're trying to do here? This code doesn't make any sense. The whole point of "using" is that you are using the object here only and then automatically getting rid of its scarce unmanaged resources, rendering it unusable. There is probably a better way to do what you want to do.

提交回复
热议问题