Date string variable name valid in debugger

Can someone tell me why the debugger treats my string variable named Date as a DateTime object?

the code:

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

See screen capture:

enter image description here

Using .NET framework 4.5, VS-2015

Thanks!

Update:

Reducing the code to the minimum possible, I found an obvious problem.

Minimum Abbreviated 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: enter image description here

It was another variable in a different context, named exactly like a string, and the debugger showed the details of another object (based on context)

+7
c # datetime visual-studio-2015
source share
2 answers
 //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
source share

When you look for variable values ​​in debug mode, it matches by name and not by memory address.

I agree with others, this can be done better, moreover, I saw this problem in previous versions (at least since 2013).

0
source share

All Articles