How to show the value of a private variable in some debug window? (C# Express)

J

Johann Schuler

Let's say I have a Person class with a private int age member variable. I
have a get and set accessor for the Age property. When I am running the code
in debug mode, I would like to have a debug window show me the value of age
(rather than the value of the Age property). Is there a way to do this?

Thanks!
 
V

Vadivel Kumar

Yes, certainly there are ways. For example you have the code similar to
this.

public class Person
{
private Int32 _Age;

public Int32 Age
{
set {
_Age = value;
System.Diagnostics.Debug.Write(_Age.ToString());
}
get {
return _Age;
}
}
}

Check out the line System.Diagnostics.Debug.Write(_Age.ToString());
which prints the value of the _Age in the debug window.

Let us know if you have any trouble in doing this.

-
Vadivel Kumar
http://www.vadivelk.net
 
J

Johann Schuler

prints the value of the _Age in the debug window

Vadivel:

I am using C# Express edition and I cannot get a "debug" window as such.
While running in debug mode, the windows I can get under Debug -> Windows
are: Output, Locals, Watch, Immediate, and Call Stack. None of these windows
will display _Age. Could this be a limitation of the Express edition?

Johann (newbie)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top