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

[FxCop.设计规则]6. 避免使用输出参数
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.
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.
It is safe to exclude a message from this rule; however, this design might cause usability issues.
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

