Review the solution for the code debugger challenge
The following example of a debug process is one possible solution for the challenge from the previous unit.
Implement the C# debugger tools to identify the issue
The following debug process implements a breakpoint and then monitors the value of x in the VARIABLES section of RUN AND DEBUG view.
Set a breakpoint on the following code line:
int x = 5;Open the RUN AND DEBUG view.
At the top of the RUN AND DEBUG view, select Start Debugging.
In the VARIABLES section of the Run and Debug view, make note of the value assigned to
x.On the Debug control toolbar, select Step Into.
Track the value assigned to
xas you step through each code line.Notice that the value of
xdoesn't change as execution enters and exits theChangeValuemethod.The
ChangeValuemethod is passed the value ofx, rather than a reference tox, so the change tovalueinside the method doesn't affect the original variablex.
Consider a code update based on debugging results
If you want the ChangeValue method to change the value in the calling code, you need to update your code. One way to achieve your intended result would be to update the ChangeValue method to return an integer value, and update the code that calls ChangeValue so that it assigns the return value to x.
For example:
int x = 5;
x = ChangeValue(x);
Console.WriteLine(x);
int ChangeValue(int value)
{
value = 10;
return value;
}
If you succeeded in this challenge, congratulations! Continue on to the knowledge check in the next unit.
Important
If you had trouble completing this challenge, maybe you should review the previous units before you continue on.