字符串变量名日期的行为怪异的调试器 [英] String variable name Date acts weird in debugger
问题描述
谁能告诉我,为什么被调试器处理我的字符串名为
变量日期
为日期时间
对象?
Can someone tell me why is the debugger handles my string
variable named Date
as a DateTime
object?
code:
public class HourRegistration
{
public string Date { get; set; }
}
请参阅屏幕捕获:
使用.NET Framework 4.5,VS-2015
Using .NET framework 4.5, VS-2015
谢谢!
更新:
由于减少了code,以尽可能小的,我发现明显的问题。
By reducing the code to smallest possible, I found to obvious problem.
最低限度减少code:
Minimally reduced code:
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
DoSomething();
}
public static void DoSomething()
{
DateTime Date = DateTime.ParseExact("asdasd", "dd/MM/yyyy", CultureInfo.InvariantCulture);
}
public class HourRegistration
{
public string Date { get; set; }
}
}
}
这是在另一个名为完全相同串上下文一个不同的变量,并且调试器显示出其他对象的细节(基于上下文)
It was a different variable in another context named exactly the same as the string, and the debugger showed the details of the other object (based on context)
推荐答案
当你正在寻找在调试模式变量的值,它的名字相匹配,而不是内存地址。
When you are looking for variable values in debugging mode, it matches by name, not by memory address.
我同意其他人,这是可以做到更好,而且我已经看到了这个问题的在previous版本(至少VS 2013)。
I agree to others, it could be done better, moreover I've seen this issue in previous versions (at least vs 2013).
这篇关于字符串变量名日期的行为怪异的调试器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!