How to see the code where a variable changed in Watch window from Visual Studio

JeffinAtl 161 Reputation points
2022-06-06T17:21:07.653+00:00

I want to see the code where a variable is changed in the watch window from Visual Studio 2019.
I can see the watch window and variable on it but can't figure out which code makes that variable is changed.
Can I trace it?

Developer technologies | Visual Studio | Debugging
Developer technologies | C#
Developer technologies | C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Anna Xiu-MSFT 31,151 Reputation points Microsoft External Staff
    2022-06-07T10:52:40.837+00:00

    Hi @JeffinAtl ,

    Welcome to Microsoft Q&A!

    For your requirement, please right-click on the variable in watch window and select the “Break When Value Changes”.
    If the value of variable is changed, the data breakpoint will stop at the code line after the value is changed.

    Sincerely,
    Anna
    *
    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread

    1 person found this answer helpful.

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.