有没有办法省略了参数? [英] Is there a way to omit out parameter?
本文介绍了有没有办法省略了参数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
假设我有一个函数退出
参数,但是我并不需要它的价值。 ?有没有办法通过,如果给定的结果无论如何都会被扔掉没有实际参数
Assume I have a function with out
parameter, however I do not need its value. Is there a way to pass no actual parameter if given result will be thrown away anyway?
对不起,实际上可以它原来是的C# 4可选输出参数
Sorry, acutally it turned out to be dupe of C# 4 Optional Output Parameters
推荐答案
您不能做到这一点,但没有规定说你必须使用回来的值。你可以简单地传递,你从来没有再次使用一个临时变量。
You cannot do this, but there's no rule saying that you have to use the value that comes back. You can simply pass a temporary variable that you never use again.
C#4.0允许可选参数,但退出
参数。不能是可选的。
C# 4.0 allows optional parameters, but out
parameters can't be optional.
编辑:顺便说一句,你也可以重载方法:
BTW, you can also overload the method:
int DoStuff()
{
int temp;
return DoStuff(out temp);
}
int DoStuff(out outParam)
{
//...
}
这篇关于有没有办法省略了参数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文