As we all know, the method of parameter passing in C # functions is passed by value and passed by reference, so what's the difference between the two ways?
parameter types in C # have value types (such as int) and reference types (for example, string)
The same parameter passes are passed by value and passed by reference
We can use 22 combinations to get 4 ways to deliver:
(1) Passing value types by value
(2) Passing reference types by value
(3) Passing value types by reference
(4) Passing reference types by reference
In general, parameters are passed by value unless a particular keyword (ref and out) is used.
"Advantages and disadvantages of passing by value"
Passing by value passes a copy. One advantage of passing replicas is that you can avoid misoperation and affect the original values. The reason is that in the body of the function being called, the value of the replica is manipulated, not the original value. Of course, the transfer copy is also flawed, the most prominent should be due to duplication of performance loss, this is particularly important in large value types.
So why is the default behavior of C # 's compiler not using passing arguments by reference? is to fear that the function mistakenly manipulated the original value. This should be similar to the C # compiler requirement to display the use of keywords (ref and out), all in order to clearly express the intent to use to avoid misoperation. Using keywords such as ref, implies that the function caller knows that in the function body there may be a statement that modifies the original value, changing the value of the parameter (or state).