+ 1
What is the difference between returning values from a function and passing by output e.g. myFunc(out a, out b)
2 ответов
+ 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.
+ 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)
}