When to use inout parameters?

前端 未结 7 1598
情书的邮戳
情书的邮戳 2020-12-13 03:15

When passing a class or primitive type into a function, any change made in the function to the parameter will be reflected outside of the class. This is basically the same t

7条回答
  •  一向
    一向 (楼主)
    2020-12-13 03:50

    Function parameters are constants by default. Trying to change the value of a function parameter from within the body of that function results in a compile-time error. This means that you can’t change the value of a parameter by mistake. If you want a function to modify a parameter’s value, and you want those changes to persist after the function call has ended, define that parameter as an in-out parameter instead.

提交回复
热议问题