Consider:
public int GetScore()
{
return this.score;
}and:
int currentScore = team1.GetScore();The runtime flow is:
caller
↓
GetScore()
↓
return this.score
↑
caller receives result
↓
currentScoreThe debugger can help you observe each stage.
Set a breakpoint before:
int currentScore = team1.GetScore();Inspect:
team1and predict:
If:
team1.score = 3predict:
returned value = 3Use Step Into at:
team1.GetScore()Inside the method, inspect:
this.scoreSuppose the debugger shows:
3Now the return statement:
return this.score;should send 3 back to the caller.
While paused inside GetScore(), the Call Stack shows:
GetScore()
callerThe caller is waiting for the method to finish.
After the return executes, GetScore() leaves the active call stack and execution resumes in the caller.
After the call completes:
int currentScore = team1.GetScore();inspect:
currentScoreIt should contain the value returned by the method.
For this example:
currentScore = 3That completes the return-value trace.
Suppose:
public int GetTotalGoals()
{
return this.homeGoals + this.awayGoals;
}If the debugger shows:
homeGoals = 2
awayGoals = 1predict:
2 + 1 = 3Then step through and inspect the receiving variable after the call.
Suppose:
public string GetAvailabilityText()
{
if (this.isAvailable)
{
return "Available";
}
else
{
return "Unavailable";
}
}First inspect:
this.isAvailableThen predict which return statement should execute.
For:
isAvailable = falsepredict:
return "Unavailable";Step through the condition and verify the selected return.
Inside the method, the source may say:
return this.score;The caller receives the current value of that expression, such as:
3The caller does not receive the source text:
this.scoreIt receives the value produced during execution.
Suppose the method correctly returns:
3but later the caller changes:
currentScoreThe return itself may be correct even though later program behavior becomes wrong.
Use the debugger to identify exactly when the unexpected value first appears.
Suppose:
public string GetGoalCategory(int goals)
{
if (goals >= 3)
{
return "High scoring";
}
return "Fewer than three";
}A call:
string category = team1.GetGoalCategory(4);can be traced as:
argument 4
↓
parameter goals = 4
↓
goals >= 3 → true
↓
return "High scoring"
↓
category = "High scoring"The debugger lets you verify that entire path.
A strong explanation is:
That describes evidence rather than guessing.