为什么.net框架指南建议您不要使用REF /输出变量?建议您、变量、框架、指南

2023-09-04 23:56:12 作者:你未来的老公

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

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.