为什么.net框架指南建议您不要使用REF /输出变量? [英] Why does the .Net framework guidelines recommend that you don't use ref/out arguments?

查看:131
本文介绍了为什么.net框架指南建议您不要使用REF /输出变量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

显然,他们是令人困惑。那是严重的原因是什么?你能想到的任何其他人吗?

Apparently, they're "confusing". Is that seriously the reason? Can you think of any others?

推荐答案

你见过有多少开发者并不真正了解REF /输出?

Have you seen how many developers don't really understand ref/out?

我使用他们,他们真的很必要的,而不是其他。他们通常只如果要有效地返回两个或多个值用 - 在这种情况下,它的身价至少的关于是否有制作方法只做一件事,而不是一种方式。有时使用REF /输出的的最合适的方法 - 不同的TryParse方法等

I use them where they're really necessary, but not otherwise. They're usually only useful if you want to effectively return two or more values - in which case it's worth at least thinking about whether there's a way of making the method only do one thing instead. Sometimes using ref/out is the most appropriate approach - the various TryParse methods etc.

这篇关于为什么.net框架指南建议您不要使用REF /输出变量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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