是否与QUOT;明"参数是坏事。NET? [英] Are "out" parameters a bad thing in .NET?

查看:144
本文介绍了是否与QUOT;明"参数是坏事。NET?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是走出去的参数是坏事。NET?关于这个主题的任何好文章/讨论?

Are "out" parameters a bad thing in .NET? Any good articles/discussions on this topic?

推荐答案

嗯,我有什么参考的文章/出来做 - 但它不讨论你是否应该使用它们

Well, I have an article on what ref/out do - but it doesn't discuss whether or not you should use them.

基本上退出参数通常要有效地从方法返回两个结果的标志。这是的一般的一个code气味 - 但也有一些情况下(最显着的TryXXX图案),你真正想要返回两条信息有充分的理由,并没有太大的意义封装在一起。

Basically out parameters are usually a sign that you want to effectively return two results from a method. That's usually a code smell - but there are some cases (most notably with the TryXXX pattern) where you genuinely want to return two pieces of information for good reasons and it doesn't make much sense to encapsulate them together.

在换句话说,避免输出/ REF在这里你可以这样做很容易,但不要去大规模走出自己的方式,以避免它们。

In other words, avoid out/ref where you can do so easily, but don't go massively out of your way to avoid them.

这篇关于是否与QUOT;明"参数是坏事。NET?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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