How to Edit a DateTime Variable During Visual Studio 2013 Debug Session

只谈情不闲聊 提交于 2020-12-16 06:30:08

问题


If I place a breakpoint and cause code execution to pause on a line where I wish to test the value of a DateTime variable, the Visual Studio 2013 debugger will display the value of my DateTime variable in the form "{10/1/2017 12:00:00 AM}" when I hover it and even allow me to begin to edit it--but when I press Enter I get the error, "Invalid expression term '{'". What is the proper way to edit a DateTime variable on the fly during a debug session?


回答1:


While execution is paused, a little datatip pop-up appears when you hover over your DateTime variable. Click the date within to begin editing it. Switch the squiggly parentheses to quotes, and surround the entire quoted date with a call to DateTime.Parse, like so:

DateTime.Parse("10/1/2017 12:00:00 AM")

You can then change the date inside the quote to whatever new date you want--and when you press Enter, the corresponding DateTime value will be inserted into your variable on the fly!




回答2:


Perhaps, this could help:

How do I enter a DateTime value in the VS QuickWatch window?

This post says that is's immutable: https://stackoverflow.com/a/489741/267000

Another way to edit it at runtime is Open Immediate Window: Debug -> Windows -> Immediate and edit with usual in C# syntax



来源:https://stackoverflow.com/questions/46182977/how-to-edit-a-datetime-variable-during-visual-studio-2013-debug-session

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!