+ 1
How is the answer 30 ?
What is the output of this code? static int Test(out int x, int y=4) { x = 6; return x * y; } static void Main(string[] args) { int a; int z = Test(out a); Console.WriteLine(a + z); } //output 30
2 Respostas
+ 9
out makes 'a' be passed by reference and does not require the variable to have an initial value. The value can be set in the method that the variable is being passed to.
This is why:
int a;
Test(out a);
Does not cause issues, even though 'a' has not been given any value.
x = 6 also makes 'a' equal to 6 since 'a' was passed by reference.
x * y is 6* 4 = 24.
z is 24 since 24 is returned.
x + a = 6 + 24 = 30.
0
thaks a lot