Difference between reference(ref) and out( passing parameter ) in C# | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Difference between reference(ref) and out( passing parameter ) in C#

13th Aug 2019, 1:01 AM
Rio Fairhall
Rio Fairhall - avatar
2 Answers
+ 2
With ref parameters, you can pass data into a method as well.
13th Aug 2019, 2:58 AM
Sonic
Sonic - avatar
+ 1
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. https://stackoverflow.com/questions/388464/whats-the-difference-between-the-ref-and-out-keywords
13th Aug 2019, 3:09 AM
Vahid
Vahid - avatar