将字符串转换为变量
这可能不可能,但对调试非常有帮助。有时程序运行时会出现随机错误。我希望能够在(字符串)中输入一些内容,然后它将获取具有该字符串名称的变量并返回其值。
int mainNumber = 89;
输入:检索mainNumber 输出:89
这样的事情可能吗?我不想为我拥有的每个变量创建调试,以免出现问题。我知道我可以等待错误发生,停止程序,进行调试并再次等待,但这会更快。
This might not be possible but it would be hugely helpful with debugging. Sometimes random bugs occur when the program is running. I'd like to be able to type something in (a string) and then it would grab a variable with the name of that string and return its value.
int mainNumber = 89;
Input: retrieve mainNumber
Output: 89
Is something like that possible? I don't want to have to create debugs for every single variable I have on the off chance something could go wrong. I know I could wait for the bug to occur, stop the program, throw a debug in and wait again, but this would be faster.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我建议阅读 .NET 中的跟踪和调试。您通常可以切换 Trace 和 从程序的配置文件中关闭和打开调试语句,因此不会影响您的运行时表现除非你想要这些转储。然后,您可以在代码中添加
Trace.Write(...)
和Debug.Write(...)
语句来提供您想要的输出。I would suggest reading up on Trace and Debug in .NET. You can typically switch Trace and Debug statements off and on from a program's config file, thus not affecting your runtime performance unless you want these dumps. Then you can sprinkle
Trace.Write(...)
andDebug.Write(...)
statements in your code to provide the output you desire.根据您的评论,听起来您需要做一些研究。以下是一些需要考虑/尝试的事情:
我过去做过的一种选择是将日志记录(通常是文本文件)添加到相关应用程序中。我在感兴趣的领域进行了日志记录,并为条目添加了时间戳。获取足够的信息,以便您可以充分识别正在发生的操作(变量/对象的状态之前/之后,识别操作的任何支持信息等)。
当报告(或重现)错误时,如果报告者提供了足够的信息(即时间、他们在做什么、应用程序特有的其他事情或他们在做什么),您可以查看日志文件并查看发生了什么在。
一旦掌握了这些信息,您就可以确定根本原因,或者将范围缩小到更具体的领域并集中精力在那里。
这可能是一个迭代过程,具体取决于应用程序有多大以及可能出现问题的区域有多大。
Based on your comment, it sounds like you're going to need to do some research. Here are some things to consider/try:
One option that I've done in the past is to add logging (usually to a text file) to the application in question. I put in logging in the areas of interest, and timestamp the entries. Grab enough information so you can adequately identify the actions that are occurring (before/after states of variables/objects, any supporting information that identifies the action, etc).
When a bug is reported (or reproduced), if the reporter gives enough information (i.e., time, what they were doing, other things particular to the app or what they were doing) you can look in your log files and see what was going on.
Once you have that information, you can either identify the root cause, or narrow it down to a more specific area and focus your efforts there.
It can be something of an iterative process, depending on how big the app is and how large the area of possible problems can be.
您需要了解
变量
,观看
和立即
Visual Studio 窗口。You need to learn about the
variable
,watch
andimmediate
windows of Visual Studio.“立即窗口”是您所寻找的吗? http://msdn.microsoft.com/en-我们/库/f177hahy(v=VS.100).aspx
Would the 'immediate window' be what you're looking for? http://msdn.microsoft.com/en-us/library/f177hahy(v=VS.100).aspx