字符串变量名称日期在调试器中很奇怪 [英] String variable name Date acts weird in debugger
问题描述
Date
作为 DateTime
对象? 代码:
public class HourRegistration
{
public string Date {get;组;
}
查看屏幕截图:
使用.NET framework 4.5,VS-2015
谢谢!
更新:
通过减少代码最小可能,我发现有明显的问题。
最小化代码:
命名空间ConsoleApplication1
{
类程序
{
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;组; }
}
}
}
截图:
另一个上下文中的变量名称与字符串完全相同,调试器显示详细信息的另一个对象(基于上下文)
当您在调试模式下查找变量值时,不是通过内存地址。
我同意其他人,可以做得更好,而且我以前的版本看过这个问题(至少与2013年)。
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; }
}
See screen capture:
Using .NET framework 4.5, VS-2015
Thanks!
Update:
By reducing the code to smallest possible, I found to obvious problem.
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; }
}
}
}
Screenshot:
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.
I agree to others, it could be done better, moreover I've seen this issue in previous versions (at least vs 2013).
这篇关于字符串变量名称日期在调试器中很奇怪的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!