cause: a public or protected method in a public type has an out parameter.
rule descriptionpassing types by reference (using out or ref) requires experience with pointers, understanding how value types and reference types differ, and handling methods with multiple return values. also, the difference between out and ref parameters is not widely understood.
when a reference type is passed "by reference," the method intends to use the parameter to return a different instance of the object. (passing a reference type by reference is also known as using a double pointer, pointer to a pointer, or double indirection.) using the default calling convention, which is pass "by value," a parameter that takes a reference type already receives a pointer to the object. the pointer (not the object to which it points) is passed by value, meaning that the method cannot change the pointer to have it point to a new instance of the reference type, but can alter the contents of the object to which it points. for most applications this is sufficient and yields the desired behavior.
if a method needs to return a different instance, use the methods return value to accomplish this. see the asp?frame=false">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... 下一页