代码分析返回有关不使用“ out”消息的建议。参数 [英] Code analysis comes back with suggestion about not using "out" parameters

查看:65
本文介绍了代码分析返回有关不使用“ out”消息的建议。参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对我创建的对象运行了VS 2008代码分析工具,并收到以下建议...

I ran the VS 2008 code analysis tool against an object I created and received the following suggestion ...


警告147 CA1021: Microsoft.Design
:考虑一个不要求
要求'returnValue'是out
参数的设计。

Warning 147 CA1021 : Microsoft.Design : Consider a design that does not require that 'returnValue' be an out parameter.

我发现输出参数非常有用,并且没有意识到它们在设计实践中被视为皱眉。我想知道是否有人可以阐明我收到此警告的原因?如果是不好的做法?为什么?

I find "out" parameters rather useful and didn't realize that they were considered as a frowned upon design practice. I wanted to know if someone could shed some light on the reason that I received this Warning? If it is bad practice? why? and what would be good practice?

我很感谢您提出任何建议。

I appreciate any advice.

推荐答案

每个代码分析警告都有相关的文档,您可以通过将警告突出显示并按 F1 来访问。您还可以右键单击该项目以获取帮助。

Every Code Analysis warning has associated documentation that you can access by highligting the warning and pressing F1. You can also right-click on the item to get help.

无论如何,这是解释该警告的文档

我会说有几种情况参数仍然是一个不错的选择-特别是在谈到TryParse编码习惯时,因为它是一种行之有效的方式,大多数人都应该理解它。

I would say that there are a few cases where out parameters are still a good choice - particularly when it comes to the TryParse coding idiom, because it's such a well-established way of doing things that most people are supposed to understand it

但是,在一般情况下,对于多个返回值,有更好的,面向对象的解决方案。

In general use, however, there are better, more object-oriented solutions to multiple return values.

这篇关于代码分析返回有关不使用“ out”消息的建议。参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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