Pass by Value and Pass by Reference

 

Arguments can be passed in two fashions: by value or reference. If you pass an argument by value, you are essentially creating a copy of the existing variable to the method being called. 

Caution It is extremely important to know that any changes made to the variable will not be returned to the calling function when you pass a variable by value! 

Arguments can also be passed must be passed by reference. This requires a couple of steps:

 

·         The variable passed must be passed by reference by using the ref keyword when you call the method.

 

·         The prototype of the method being called must expect a reference type and have the ref keyword in the method prototype.

 

By passing arguments by reference, you are allowing the called function to make modifications to the object being passed, and those modifications will be present when the called function returns.