Click here to Skip to main content
15,892,059 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am trying to debug my code by seeing what the variables are in real time. I want to do this without the use of Console.WriteLine, AppendFile, etc for efficiency reasons and was wondering if there is an easy way to watch variables in Visual Studio.

Any help would be appreciated!

What I have tried:

I looked at some of the microsoft tutorials, but what I have seen involves setting up breakpoints such as Set a watch on variables - Visual Studio (Windows) | Microsoft Docs[^]

I do not want the code to stop however, I want to be able to view values without impacting efficiency as much as ConsoleWritelines or AppendFiles
Posted
Updated 27-Feb-22 22:13pm

When I want to observe variables during runtime I use
Debug.Write(vairiableToWatch);

This will print the values to the VS output window within Visual Studio.
 
Share this answer
 
Comments
Admin BTA 25-Feb-22 12:53pm    
Most appreciated S Houghtelin!
Maciej Los 27-Feb-22 11:32am    
5ed!
It really wouldn't work too well if you tried to show the numbers in real time - the processor is far too fast for changes to be at all visible, let alone readable, but would still impact performance quite badly.

What you can do though is put a breakpoint into your code so the execution stops while you look at the variable content, and then either let it run on, or step through your code line by line to see what path it is taking and why.
 
Share this answer
 
Comments
Admin BTA 25-Feb-22 12:53pm    
Most appreciated OriginalGriff!
OriginalGriff 25-Feb-22 13:25pm    
You're welcome!
Maciej Los 27-Feb-22 11:32am    
5ed!
It sounds like you're looking for a tracepoint:
Log info with tracepoints - Visual Studio (Windows) | Microsoft Docs[^]

It's essentially a breakpoint which doesn't break; it just writes out an expression to the debug output window, which can include the value of one or more variables.
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900