返回值参考论据或结构 [英] Return values with reference arguments or by structure
本文介绍了返回值参考论据或结构的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在什么situtations是最好用的参考参数返回值?
子实例(按地址值作为整数)
值= 3
结束小组
在什么情况下是它最好的返回值(也许在更复杂的类型的结构)?
功能示例()作为整数
返回3
结束功能
解决方案
当你想返回一个状态或操作状态以及从操作的结果。
想TryParse..it的返回转换结果为真或假,它通过一个引用变量返回转换的结果。
昏暗数作为整数
昏暗的结果作为布尔= Int32.TryParse(值,数量)
公共共享功能的TryParse(_
参考译文]字符串_
< OutAttribute>为ByRef结果作为整数_
)为布尔
但除此之外,正如其他人建议我不会被裁判使用了很多,它可以使code非常难以阅读和调试。
In what situtations is it best to use reference arguments to return values?
Sub Example(byref value as integer)
value = 3
End Sub
In what situations is it best to return the value (perhaps in a structure for more complex types)?
Function Example() as integer
return 3
End Function
解决方案
when you want to return a state or status of an operation plus the result from the operation.
think of TryParse..it returns a conversion result as true or false and it returns the converted value by a ref variable.
Dim number As Integer
Dim result As Boolean = Int32.TryParse(value, number)
Public Shared Function TryParse ( _
s As String, _
<OutAttribute> ByRef result As Integer _
) As Boolean
but other than that, as others suggested i would not use by ref a lot, it can make code very hard to read and debug.
这篇关于返回值参考论据或结构的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文