Tuesday, September 9, 2014

Challenge: Something is being calculated at the same line it is being returned and you want to see what the calculated value is in Visual Studio 2013.

If you set a breakpoint at the line in question, there is nothing you may easily mouse over to see the calculated value. So what do we do?

I am embarrassed to admit that I used to just break the one line of code into two. I'd cast the calculation to a variable and then return the variable in a second line of code while placing a breakpoint at the second line so that I could tell what is in the variable at the first line. In the example here we get at the integer 55 which is what we want... but there has to be a better way, right?

Sticking with one line of code, you may highlight (drag the cursor over to make a selection) just the calculation, right-click upon it, and pick: "Add Watch"

The "Watch" pane will appear at Visual Studio's base, and, look, there is the number 55!

No comments:

Post a Comment