How can I trace a variable at runtime in C#?

前端 未结 5 1785
余生分开走
余生分开走 2020-12-18 05:43

How can I track a variable\'s values as they change, at runtime, in C#? I\'m interested in the same functionality that the debugger provides when I\'m tracing a variable thr

5条回答
  •  青春惊慌失措
    2020-12-18 06:47

    As others mentioned a mechanism like that makes only sense when using properties. In .NET you can then make use of the INotifyPropertyChanged interface.

    For a sample how to implement it see

    How to: Implement the INotifyPropertyChanged Interface

    The referenced article talks explicitly about Windows Forms, but you are not bound to that (the interface is actually declared in the System.ComponentModel namespace in System.dll). In fact, this interface is widely used for data binding scenarios, e.g. in WPF.

提交回复
热议问题