When choosing between "Out" and "Ref" parameters, unless "Ref" is specially required, the preset selection is "OUT". The difference between
out and Ref
"Ref" allows method modification to modify the original value of the variable transmitted as a parameter, while "OUT" is prohibited from this ability. When data transmission involves data transmission of cross -process or cross -machine, this difference becomes vital, because the initial value of the marshal may lead to unnecessary processing.
Consider the following scene:
person.getbothnames (out a, out b); Assume that "Person" is an object. "Getbothnames" is a method for retrieved two values. The initial value of "A" and "B" has nothing to do with the operation of the method. In this case, using "IN" or "OUT" is a preferences, and "OUT" is a recommended option to eliminate useless marshals that are used in initial values.
person.GetBothNames(out a, out b);
In short, in most cases, if the initial variable value is not required, "OUT" is a better choice; when such modifications need to be performed, "Ref" becomes necessary.
Disclaimer: All resources provided are partly from the Internet. If there is any infringement of your copyright or other rights and interests, please explain the detailed reasons and provide proof of copyright or rights and interests and then send it to the email: [email protected] We will handle it for you as soon as possible.
Copyright© 2022 湘ICP备2022001581号-3