C# FAQ: What is the difference between the out and ref parameter modifiers
Microsoft .NET Framework, ASP.NET, Visual C# (CSharp, C Sharp, C-Sharp) Developer Training, Visual Studio
| CSharp-Online.NET:FAQs |
| edit |
[edit]
What is the difference between the out and ref parameter modifiers?
Both the out and ref modifiers can be applied to method arguments. And, both imply that the argument will be passed by reference—either as a reference to a value type variable or to a reference type variable. However, the out parameter enables passing in an uninitialized variable and guarantees that it will come back with set to a value.
int integer; AccessByReference (out integer); // on return, integer has been set to an int value
For more information on pass by reference and pass by value, consult Pass-by-Value and Pass-by-Reference.
[edit]
See also
- C# Keywords
- How can I declare inout arguments in C#?
- How do I declare an
outvariable? - Pass-by-Value and Pass-by-Reference