What is the difference between out and ref parameters in .NET?Both ref
and out parameters are used to return multiple values from a method. They
are used for the same purpose but the only difference is that: ref parameters
have to be initialized before being passed as the method parameter but
the out parameters need not be initialized.
Here is an example to demonstrate it: class sampleClass
{ Output of this code will be: The Values are: 200, 400 Note that
in this example the out parameter value1 is not initialized and the ref
parameter value2 is initialized to 0 before passing it to getValues method.
|