out keyword causes arguments to be passed by reference only difference is that out parameters doesn\’t require initialization like ref parameter and out parameter must assigned/initialize inside method.
Points to remeber
- The
refandoutkeywords cause different run-time behaviour, they are not considered part of the method signature at compile time. You can not overload method byrefandout.
class Example
{
// Compiler error CS0663: "Cannot define overloaded
// methods that differ only on ref and out".
public void Method1(out int i) {
i = 1;
}
public void Method1(ref int i) { }
}
- Property, indexers, dynamic types can not be passed as
reforoutparameter.
Asyncmethods, which you define by using theasyncmodifier can not usereforout.- Iterator methods, which include a yield return or yield break statement can not use
reforout.
