Tuesday, February 06, 2007

Visual Studio's (or .NET's) equivalent of GDB's watch

People coming in from native background (I mean those who have been using GDB extensively) might get perplexed by the fact that they can't watch a variable in .NET. Reason being, when you ask the debugger to watch a particular variable or object (to let you know when a particular value is accessed or modified) you are basically asking the debugger to watch a physical address. And the fact that garbage collector can reshuffle the objects in memory obviates this possibility.

So what do you do? You refactor the code, define brand new get/set properties for that variable and start accessing it through them. Now you can put in break-points in the get and set properties.

No comments: