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?
Debug -> Windows -> Immediate -> type code to access your members:
[>] MyClass.MyStaticValue [ENTER]
Or put them in Watch window.
Notes:
- You might need to add namespace too, i.e.
MyNameSpace.MyClass.MyStaticValue
- 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
).
? global::fully.qualified.Object.Property
. Without the global
, I'd get unknown identifier errors despite no conflicts. –
Bluish One way is to use Immediate Window
as @Alexei says.
Second way is to use QuickWatch
window as below:
Put a breakpoint in the class for which you want to evaluate static or any other variables/fields/properties and run the application.
Then when the breakpoint is hit, right click on any variable/field/property in a class and select QuickWatch
. Now, type <ClassName.StaticVarName
> in the QuickWatch window textbox and press enter and you should be able to see the value as below screenshot displays:
static class
then you're SOL. It's surprising that QuickWatch won't let you do that. –
Proto In Visual Studio 2017, when you break the code execution you can see the values of static variables when you hover over their declarations in the source code there will be small pop-up like this:
- You can right click this pop-up and add the variable to watch window.
- You can click the pin to keep the variable pop-up from disappearing.
Do you have Costura.Fody installed? I had the same issue in a project and found that it was causing static class variables to not be shown, as well as having to rebuild the project each time.
As far as I know, there's no way to show all static members of a class. Single items can be displayed in Watch or QuickWatch the Windows. my workaround is the implementation of a status method, with return type 'string', which then can be used in the Immediate window. For performance reasons, I don't use a property. If this does not concern you, you could overload the ToString() method. Then the debugger will always show its result in all relevant windows.
© 2022 - 2025 — McMap. All rights reserved.
ClassName.StaticVarName
> inQuickWatch
window doesn't show the value? – Downstage