What is the difference between returning values from a function and passing by output e.g. myFunc(out a, out b) | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

What is the difference between returning values from a function and passing by output e.g. myFunc(out a, out b)

1st Jul 2017, 7:46 AM
Haider Ali
Haider Ali - avatar
2 Answers
+ 3
In fact most of the time, you will need to split your programs into small blocks of processing, and as you reuse the same function several times, it is better to set it to return the value, than just display it on the screen.
1st Jul 2017, 7:50 AM
Juliano Ventola
Juliano Ventola - avatar
+ 1
It is the same just another way if doing it. You will find that returning the value is the shortest and clearest way of coding. x = func (); instead of int x; func(out x); but sometines I like the out parameter for example when returning multiple values or returning bool to say the function was executed succesfully and returning the value in a out-parameter. bool func (out x); bool succes; int x succes = func (out x); if (succes) { Console.WriteLine ({0}, x) }
1st Jul 2017, 11:36 AM
sneeze
sneeze - avatar