what is the pros and cons of using out parameter

前端 未结 4 1097
囚心锁ツ
囚心锁ツ 2021-01-19 10:22

Anyone can point out the pros and cons of the out parameter. When it is preferred to use out parameter rather than just to return a value.

4条回答
  •  伪装坚强ぢ
    2021-01-19 11:02

    Out parameters effectively allow you to return multiple values from a method, and this is generally preferable to returning an arbitrary struct or tuple which contains multiple values.

    One might argue that it's easier to overlook the possible side effects of a function which uses an out parameter, as it departs from the traditional 'multiple parameters, one return value' model. But I honestly think that the out keyword coupled with a method post-condition makes the programmer's intention quite clear.

提交回复
热议问题