(ref) VS (out) | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 3

(ref) VS (out)

i want to ask what the defferances between passing variables to functions by out word and ref word? THANK YOU!

15th Feb 2019, 7:14 PM
Abderrahmane SAOUDI
Abderrahmane SAOUDI - avatar
8 Answers
+ 4
@ Ollie Q I do not agree with you, on the ref part. by val : doesn’t change the value for the rest of the program But the ref keyword is especially used for changing the value for the rest of the program. Have a look at this example code. https://code.sololearn.com/c0mzKfHb0nuM
15th Feb 2019, 8:42 PM
sneeze
sneeze - avatar
+ 7
out parameter can be uninitialized ref must get initialized
16th Feb 2019, 4:24 AM
Muhd Khairul Amirin
Muhd Khairul Amirin - avatar
+ 6
sneeze your answers better than mine and also more acurate ans also nice program. p.s thanks for helping me with the NuGet library last week
15th Feb 2019, 11:39 PM
Ollie Q
Ollie Q - avatar
+ 3
Hi Star PRO X the out keyword changes the value of the varible in the function and outputs the varible in the program. the ref keyword acepts a varible into the function but doesn’t change the value for the rest of the program i hope this helps
15th Feb 2019, 7:33 PM
Ollie Q
Ollie Q - avatar
+ 1
i see that out in your example that out and ref working same... they changed the value of given variable on calling that's all....
16th Feb 2019, 5:17 AM
Abderrahmane SAOUDI
Abderrahmane SAOUDI - avatar
+ 1
Ollie Q keep coding, keep learning.
16th Feb 2019, 10:26 AM
sneeze
sneeze - avatar
0
Star PRO X Notice that the out parameter cannot be initialized!! This is a huge difference between and ref and out.
16th Feb 2019, 10:23 AM
sneeze
sneeze - avatar
0
Thank you guys i understand them 🙏💕
22nd Jun 2019, 7:12 AM
Abderrahmane SAOUDI
Abderrahmane SAOUDI - avatar