返回使用创建的对象

编程入门 行业动态 更新时间:2024-10-11 21:30:27
本文介绍了返回使用创建的对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我在使用,并返回该对象的功能return.Will这个事业之前,我尝试在其他功能使用返回的值状物体的任何问题将得到处理的一部分创建一个对象(OBJ下)?

使用(为MyObject OBJ =新MyObject来()) {。 。 。 返回OBJ; }

解决方案

这会不会导致类似对象中的任何问题都会进行处理之前,我尝试在其他功能使用返回的值?

您能解释一下你想要做什么这里?此代码没有任何意义。整个使用的的点的是,你的使用的对象的这里只的,然后自动摆脱其稀缺的非托管资源,使其无法使用。有可能是一个更好的方法去做你想做的事情。

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 use returned value in another function ?

using (MyObject obj = new MyObject()) { . . . return obj; }

解决方案

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.

更多推荐

返回使用创建的对象

本文发布于:2023-08-04 21:46:19,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1299883.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:对象

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!