For Debug C# console applications (Get started with C#, Part 6) - Implement the Visual Studio Code debugging tools for C# - Unit 10, shall the solution be edited?
In the previous session, it was taught that int is a value type.
So in the debug solution, even though x is assigned 10 in the “ChangeValue” method, the global value remains unchanged, so x is still 5.
Other than editing the method so it returns a value, I think line 6 should be changed to:
x = ChangeValue(x);
Right?
Exercise - Complete a challenge activity using the debugger
Solution of the debugger challenge
Could you please attach some code in your question? No idea what line 6 is. The solution code is:
int x = 5;
x = ChangeValue(x);
Console.WriteLine(x);
int ChangeValue(int value)
{
value = 10;
return value;
}
The assignment in line 2 is to change the value of x.
Yes, because I have sent feedback to Microsoft Learn and asked them to correct the code.
Originally in the solution, Line 2 was just
ChangeValue(x);
(the original solution only added a return value to the method, but did not assign the return value to x, the staff has since corrected the error)
1 Like
Nice!
Thanks for your contribution!