A breakpoint lets you see a value inside a method before it crosses back to the caller. In Zoo, Animal calculates a food portion using its own fields. Set a breakpoint inside GetPortionSize() and another just after the call in the feeding handler.
public double GetPortionSize()
{
double portion = this.Weight * this.PortionSizePercentage;
return portion;
}
// In a feeding handler:
double foodWeight = this.ComoZoo.FeaturedAnimal.GetPortionSize();Step into the call to inspect this.Weight and this.PortionSizePercentage. After the multiplication, inspect portion. Step out of the method; the returned number becomes the caller’s foodWeight. The two variables live in different methods even when they hold the same number.
Use Locals while paused in Animal to inspect the method’s local variable, then use Locals again in MainWindow to inspect foodWeight. In Date Night, follow the same pattern for any method that returns a calculated total: inspect the inputs, the value at return, and the receiving variable.
If the value changes unexpectedly, identify the first line where it differs from your prediction. Check whether the caller used the returned value or accidentally reused an earlier local value.
For an animal with Weight 35.3 and PortionSizePercentage 0.016, predict a portion of 0.5648 before running the program. While paused, distinguish the field on this from the local portion. If those values agree but foodWeight differs, check the object on which the caller invoked the method and whether a second assignment changed foodWeight afterward.