what is use of out parameter in c#

后端 未结 9 1179
南方客
南方客 2021-02-07 16:27

Can you please tell me what is the exact use of out parameter?

Related Question:
What is the differen

9条回答
  •  情话喂你
    2021-02-07 16:49

    from http://msdn.microsoft.com/en-us/vcsharp/aa336814.aspx

    One way to think of out parameters is that they are like additional return values of a method. They are very convenient when a method returns more than one value, in this example firstName and lastName. Out parameters can be abused however. As a matter of good programming style if you find yourself writing a method with many out parameters then you should think about refactoring your code. One possible solution is to package all the return values into a single struct.

    In contrast ref parameters are considered initially assigned by the callee. As such, the callee is not required to assign to the ref parameter before use. Ref parameters are passed both into and out of a method.

提交回复
热议问题