Data Structures and Algorithms
with Object-Oriented Design Patterns in C# |
C# actually supports three different flavours of pass-by-reference: ref , in , and out . The latter two are special cases of the first.
An in parameter is a parameter that is passed by reference in to a method. Specifically, the actual parameter must already have a value and that value is assigned to the formal parameter of the method. Furthermore, it is not possible to assign a new value to an in parameter in the body of the method.
An out parameter is a parameter that is passed by reference out from a method. Specifically, the formal parameter must be assigned a value by the method before the method is called, and that value is then returned to the actual parameter of the calling method. It is not possible to use the value of an out parameter in the method body until a value has been assigned to that parameter.