can somebody explain me what does “passing by value” and “Passing by reference” mean in C#?

前端 未结 4 1640
悲哀的现实
悲哀的现实 2021-01-20 00:50

I am not quiet sure about the concept of \"passing by value\" and \"passing by reference\" in c#. I think Passing by value mean :

    int i = 9;
4条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2021-01-20 01:21

    In simple terms...

    "Passing by value" means that you pass the actual value of the variable into the function. So, in your example, it would pass the value 9.

    "Passing by reference" means that you pass the variable itself into the function (not just the value). So, in your example, it would pass an integer object with the value of 9.

    This has various consequences, and each is useful in different situations.

    This answer has more thorough information: What's the difference between passing by reference vs. passing by value?

提交回复
热议问题