0
Return value in C#
I don't think I fully understand the return code. What is it used for? Would the code below run? int y = 2 int x = 6 int z = y + x return z;
1 Resposta
+ 1
return is intended for use in a function. For example, if we encase your code in a function:
static int func()
{
int y = 2;
int x = 6;
int z = y + x;
return z;
}
Now, if we call this, we must place it in a variable, because return will return an integer value.
int num = func();
And now, we can print mum's value to the console. The console will print out 8 as a result.