2015-08-14 18 views
7

有人能告訴我爲什麼調試器會將我的string變量名爲Date作爲DateTime對象處理?字符串變量名日期在調試器中很奇怪

代碼:

​​3210

見截屏:

enter image description here

使用.NET Framework 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

它是在名爲完全相同字符串另一個上下文中的不同變量,調試器顯示出其他對象的詳細信息(基於上下文)

+2

你有什麼設置?你有沒有安裝任何自定義的可視化工具?這是什麼類型的應用程序? (如果你可以在控制檯應用程序中重現這一點,這將是特別有趣的。) –

+1

我目前無法重現這一點 - 說實話,它甚至不清楚上下文是什麼 - 目前在'Date' getter中停止執行?別的地方? (我想知道它正在查看哪個實例...) –

+0

我正在減少不必要的代碼。調試某人的代碼。試圖製作一個小型控制檯應用程序來隔離問題。 – DDan

回答

0
//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. 
0

當您在調試模式下查找變量值時,它與na我,而不是通過內存地址。

我同意別人,它可以做得更好,而且我在之前的版本中看到過這個問題(至少vs 2013)。