什么是使用了参数的优劣 [英] what is the pros and cons of using out parameter
问题描述
任何人都可以点出了参数的优劣。当它pferred使用out参数而不是只返回一个值$ P $。
Anyone can point out the pros and cons of the out parameter. When it is preferred to use out parameter rather than just to return a value.
推荐答案
我会建议采取一看的的TryParse 方法上内置的类型,如int类型。返回值是一个布尔值,表明成功,同时该值通过输出参数返回。这种结构使得它用于调用这个方法在一个循环结构,其中另一种返回类型会/可能会使其更复杂一点。
I would suggest taking a look at the TryParse methods on the built in types like int. The return value is a bool to indicate success while the value is returned via an out parameter. This construct makes it useful to call this method in a looping construct where another return type would/might make it a bit more complicated.
在进一步思考1 CON可能只保留增加了参数的方法,而不是正确地封装逻辑的趋势。
On further reflection one con could be a tendency to just keep adding out parameters to a method instead of properly encapsulating the logic.
这篇关于什么是使用了参数的优劣的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!