Skip to main content
C# / .NET Output Prediction Hard +35 XP

Value vs Reference

What is x after this code?

C# / .NETRead-only
int x = 10;
void Change(int n) { n = 99; }
Change(x);
Console.WriteLine(x);

What is the output?

Show answer and explanation

Answer: 10

int is a value type. It's passed by copy. Changing n inside Change() does not affect x outside.

Hint: Is int a value type or reference type?

What this challenge tests

Output Prediction in C# / .NET: value-types, reference-types.

Related challenges