Click here to Skip to main content
Click here to Skip to main content

Modifying Variable values without leaving your Debugging Session

By , 18 Aug 2012
 

Sometimes during debugging of your code, you have to modify value for a particular variable. In a typical debugging session, you will first stop that debugging, make code changes and then start debugging again. But there are few other quick ways of modifying variable values without stopping and re-starting debugging session. Let’s say you have a Point class with an overloaded + operator as shown below.

class Point
{
 public int X { get; private set; }
 public int Y { get; private set; }

 public Point(int x, int y)
 {
  this.X = x;
  this.Y = y;
 }

 public static Point operator +(Point P1, Point P2)
 {
  return new Point(P1.X + P2.X, P1.Y + P2.Y);
 } 
}

Let’s say we want to modify the value of P1.X to something else in the overloaded + operator. I will show you couple of ways of doing it without stopping debugging session. First is from Locals window. You can not only inspect local variables through this window but you can also modify values for these variables. In order to modify the value of variable, you have to right click and then select Edit Value option as shown below.

After selecting this menu option, we modify the value of P1.X to 100. Once this change is made, the updated value will be shown in red within Locals as shown below.

Another way of changing variable values is by writing code in Intermediate Window. As shown in figure below, we have updated the value of P1.X in Intermediate Window by writing P1.X = 500; in Intermediate window. This change is reflected in Locals window as well.

One more way of doing it is using Datatips. If you hover your mouse the P1.X in the code, a small window will appear showing the value of this variable (as shown in figure below).  

At this point, you can just double click on the value 10 and modify to whatever value you need. As shown in figure below, I changed the value to 900. Once this value is modified, it will be displayed in red within the data tip and in Locals window.

I hope you will find this tip helpful.

History

First Version: 17 August 2012

Second Version: Update to include DataTips based on feedback from varun_minpal.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

About the Author

Kamran Bilgrami
Architect
Canada Canada
Member
Kamran Bilgrami is a seasoned software developer with background in designing mission critical applications for carrier grade telecom networks. More recently he is involved in design & development of real-time biometric based security solutions. His areas of interest include .NET, software security, mathematical modeling and patterns.
 
He blogs regularly at http://WindowsDebugging.Wordpress.com

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
Hint: For improved responsiveness ensure Javascript is enabled and choose 'Normal' from the Layout dropdown and hit 'Update'.
You must Sign In to use this message board.
Search this forum  
    Spacing  Noise  Layout  Per page   
GeneralMy vote of 2memberRahul.KumarSharma18 Aug '12 - 21:02 
SuggestionAnother shortcut for the same thing.membervarun_manipal18 Aug '12 - 5:38 
GeneralRe: Another shortcut for the same thing.memberKamran Bilgrami18 Aug '12 - 8:25 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Permalink | Advertise | Privacy | Mobile
Web01 | 2.6.130523.1 | Last Updated 18 Aug 2012
Article Copyright 2012 by Kamran Bilgrami
Everything else Copyright © CodeProject, 1999-2013
Terms of Use
Layout: fixed | fluid