c# - 字符串变量名称 Date 在调试器中表现得很奇怪

标签 c# .net datetime visual-studio-2015

有人能告诉我为什么调试器会处理我的 string变量命名 Date作为 DateTime目的?

代码:

public class HourRegistration
{
    public string Date { get; set; }
}

请参阅屏幕截图:

enter image description here

使用 .NET 框架 4.5,VS-2015

谢谢!

更新:

通过将代码减少到尽可能小,我发现了一个明显的问题。

最小化代码:
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; }
        }
    }
}

截屏:
enter image description here

它是另一个上下文中的不同变量,名称与字符串完全相同,调试器显示了另一个对象的详细信息(基于上下文)

最佳答案

//There in your above question you are creating a new object with datatype as datetime and variable as Date but this Date is not the one you described in your model.For that you have to do something like below:


HourRegistration model = new HourRegistration ();
     model.Date = DateTime.ParseExact("asdasd", "dd/MM/yyyy", CultureInfo.InvariantCulture).ToString();

//But this code gives an error since you cannot pass a string value to date.It makes no sense.

关于c# - 字符串变量名称 Date 在调试器中表现得很奇怪,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32005674/

相关文章:

c# - 如何比较T与T?

java - 为什么以毫秒为单位添加时间会显示不正确的结果?

python - 如何测试变量是否为 pd.NaT?

c# - 如何在 WPF 的 tabItem 中控制焦点

c# - 从 "TimeSpan"转换为 "Long"

.net - 如何为 MailMessage ReplyTo 属性分配值?

.net - Delphi 7 中的 Soap 信封 header 不包括 utf-8 编码。我该如何修改它?

php - 在 PHP 中增加日期的最简单方法?

c# - 如何将符号 - "† "转换为 HTML 代码?

c# - 为什么 Winforms.Button.Text 适用于 DataBinding 而不适用于 ImageKey?