显示报警功能,当结果不赋给变量 [英] Showing warning when function result is not assigned to variable

查看:111
本文介绍了显示报警功能,当结果不赋给变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个返回修改的对象的副本调用该函数的函数。我经常做这样的事情:

I have a function that returns modified copy of object which called this function. I often do something like this:

obj = obj.Foo(param);



不要问为什么,我只是不得不这样做。但有时我(和其他人)忘了分配函数的结果,这样做的:

Don't ask why, I simply have to. But sometimes I (and others) forgot to assign function result, doing this:

obj.Foo(param);



这多次导致费时调试。

which repeatedly leads to time-consuming debuging.

有没有办法显示一个警告或错误时,每个函数结果不分配
到一个变量的时间? ?或其他任何建议,如何来解决这个问题。

Is there any way to show an warning or error every time when function result is not assigned to a variable? Or any other suggestions how to solve this issue?

推荐答案

您可以使用一个out参数,因此呼叫是这样的:

You could use an out parameter, so the call would look like this:

obj.Foo(param, out obj);

这篇关于显示报警功能,当结果不赋给变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆