什么是在C#中使用out参数 [英] what is use of out parameter in c#
本文介绍了什么是在C#中使用out参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
能否请你告诉我什么是确切的使用 退出
参数?
相关问题:
ref和out之间的差异是什么? (C#)
解决方案
良好的使用退出
参数的最好的例子是在的TryParse
的方法。
INT结果= -1;
如果(!Int32.TryParse(SomeString,出结果){
//登录错误的输入
}
返回结果;
使用的TryParse
而不是 parseInt函数
消除了需要处理异常,使code更优雅
的退出
参数基本上是允许从一个方法不止一个返回值。
Can you please tell me what is the exact use of out
parameter?
Related Question:
What is the difference between ref and out? (C#)
解决方案
The best example of a good use of an out
parameter are in the TryParse
methods.
int result =-1;
if (!Int32.TryParse(SomeString, out result){
// log bad input
}
return result;
Using TryParse
instead of ParseInt
removes the need to handle exceptions and makes the code much more elegant.
The out
parameter essentially allows for more than one return values from a method.
这篇关于什么是在C#中使用out参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文