In general, read my article on parameter passing .
Main idea:
If the argument is passed by reference, then changes in the parameter value inside the method also affect the argument.
The subtle part is that if the parameter is a reference type, then do:
someParameter.SomeProperty = "New Value";
does not change the value of the parameter. The parameter is just a reference, and what is related to the parameter does not change above, but only the data inside the object. Here is an example of a true change in a parameter value:
someParameter = new ParameterType();
Now for examples:
A simple example: passing int by reference or by value
class Test { static void Main() { int i = 10; PassByRef(ref i);
A more complex example: using reference types
class Test { static void Main() { StringBuilder builder = new StringBuilder(); PassByRef(ref builder);
Jon skeet
source share