编程资料集中营
 | 网站首页 | 文章中心 | 编程资料2 | 软件下载 | BT下载 | 八卦星闻 | 音乐在线 | 在线游戏 | 免费电影 | 进入问吧 | 
[FxCop.设计规则]6. 避免使用输出参数,6.避免使用输出参数原文引用:AvoidoutparametersTypeName:AvoidOutParametersCheckId:CA1021Category:Microsoft.DesignMessageLevel:WarningCertainty:50%BreakingChange:BreakingCause:Apublicorprotectedm,
您现在的位置: 编程资料,学习资料,c,c++,vc,vc++,java,jsp,j2ee,j2me,asp,php >> 文章中心 >> .NET 专区 >> NET 技术 >> 文章正文
【字体:
[FxCop.设计规则]6. 避免使用输出参数   进入问吧

本站地址:http://www.bajiao123.com

作者:admin    文章来源:本站    点击数:    更新时间:2007-6-10    

[FxCop.设计规则]6. 避免使用输出参数

a method needs to return a different instance, use the method´s return value to accomplish this. See the System.String class for a wide variety of methods that operate on strings and return a new instance of a string. Using this model, it is left to the caller to decide whether the original object is preserved.

While return values are commonplace and heavily used, the correct application of out and ref parameters requires intermediate design and coding skills. Library architects designing for a general audience should not expect users to master working with out or ref parameters.

How to Fix Violations

To fix a violation of this rule caused by a value type, have the method return the object as its return value. If the method must return multiple values, redesign it to return a single instance of an object that holds the values.

To fix a violation of this rule caused by a reference type, make sure that returning a new instance of the reference is the desired behavior. If it is, the method should use its return value to do so.

When to Exclude Messages

It is safe to exclude a message from this rule; however, this design might cause usability issues.

Example Code

Example

The following library shows two implementations of a class that generates responses to user´s feedback. The first implementation (BadRefAndOut) forces the library user to manage three return values. The second implementation (RedesignedRefAndOut) simplifies the user experience by returning an instance of a container class (ReplyData) that manages the data as a single unit.

[C#]

us

上一页  [1] [2] [3] [4] [5] [6] [7] [8] [9] [10]  ... 下一页  >> 

   

进入问吧

本站地址:http://www.bajiao123.com

文章录入:admin    责任编辑:admin 
编程资料集中营