lenelex.com
Home
Quizzes
Games
Register
Log in
Question 1 of 15
What is the output of the following program?
class Program { static void Main() { int a = 2, b = 2; Multiply( a, ref b ); Console.WriteLine($"{a}, {b}"); } static void Multiply( int a, ref int b) { a *= b; b *= a; } }
A. 2, 4
B. 2, 8
C. 2, 2
D. 4, 8
Passing a value-type variable by reference
When passing a value-type variable to a method by reference, any changes that take place in the method affect the original variable in the calling program.
Links:
The [ref] Keyword
The Binary Multiplication Assignment Operator