Basically both ref
and out
for passing object/value between methods
The out keyword causes arguments to be passed by reference. This is like the ref keyword, except that ref requires that the variable be initialized before it is passed.
out
: Argument is not initialized and it must be initialized in the method
ref
: Argument is already initialized and it can be read and updated in the method.
What is the use of “ref” for reference-types ?
You can change the given reference to a different instance.
Did you know?
Although the ref and out keywords cause different run-time behavior, they are not considered part of the method signature at compile time. Therefore, methods cannot be overloaded if the only difference is that one method takes a ref argument and the other takes an out argument.
You can't use the ref and out keywords for the following kinds of methods:
Properties are not variables and therefore cannot be passed as out parameters.