Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to see the values of static variables at runtime in visual studio

The question pretty much explains what I want to do. I have several projects in c# which constitute the solution and I want to view the values of static variables at runtime in visual studio. Is there a way to do that?

like image 835
Victor Mukherjee Avatar asked Feb 14 '13 06:02

Victor Mukherjee


People also ask

How do I see variable values in Visual Studio?

If you want to continue to watch a variable, you can add it to a Watch window from a data tip. Right-click the variable in the data tip, and select Add Watch. The variable appears in the Watch window. If your Visual Studio edition supports more than one Watch window, the variable appears in Watch 1.

How do you view static class variables?

A static member variable: • Belongs to the whole class, and there is only one of it, regardless of the number of objects. Must be defined and initialized outside of any function, like a global variable. It can be accessed by any member function of the class. Normally, it is accessed with the class scope operator.

Can we change static variable at runtime?

Static methods cannot access or change the values of instance variables or the this reference (since there is no calling object for them), and static methods cannot call non-static methods.

How do you access static variables?

Static variables can be accessed by calling with the class name ClassName. VariableName. When declaring class variables as public static final, then variable names (constants) are all in upper case. If the static variables are not public and final, the naming syntax is the same as instance and local variables.


1 Answers

Debug -> Windows -> Immediate -> type code to access your members:

[>] MyClass.MyStaticValue [ENTER]

Or put them in Watch window.

Notes:

  • more information can be found on MSDN - Immediate Window
  • you may need to use global:: prefix if your class not found by just providing namespace (global::MyClass.MyStaticValue).
like image 153
Alexei Levenkov Avatar answered Sep 28 '22 22:09

Alexei Levenkov