Passing by value means a copy of an argument is passed. Changes to that copy do not change the original.
Using the OUT
keyword is useful if you have a method that you need to return more than one value. For example, look at methods like int.TryParse()
.
Using REF
is more for explicitness of objects. Keeping in mind that any non-primitive passed into a method is inherently passed by reference there's not a lot of need for it in normal managed code. By declaring the REF keyword you're stating that the parameter will likely be modified in the body of the method and thus the calling code should be aware of it (thus why you have to explicitly add the ref
in the calling code as well.