What’s the difference between the ‘ref’ and ‘out’ keywords



Concept 001 :

ref tells the compiler that the object is initialized before entering the function, while out tells the compiler that the object will be initialized inside the function.
So while ref is two-ways, out is out-only.
Concept 002 :
The ref modifier means that:
  1. The value is already set and
  2. The method can read and modify it.
The out modifier means that:
  1. The Value isn’t set and can’t be read by the method until it is set.
  2. The method must set it before returning.
 
For more detail click here.

Leave a Reply