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 = a; ByRef(ref a); ByVal(b); Console.Write($"{a}{b}"); } static void ByRef(ref int p) { p *= 2; } static void ByVal(int p) { p *= 2; } }
A. 22
B. 44
C. 42
D. 24
Passing a value-type variable by value
Passing a value-type variable to a method by value means passing a copy of the variable to the method. Any changes to the parameter that take place inside the method have no affect on the original data.
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