There is no actual issue here but the perceived difference is due to the fact that VB supports Date
literals where C# does not. Both C# and VB support literals for numeric types, strings, Booleans, etc.
var str = "Hello World";
var num = 100;
var flag = true;
Dim str = "Hello World"
Dim num = 100
Dim flag = true
Only VB supports literals for dates though. For instance, in C#, you would have to do something like this for a hard-coded date:
var dt = new DateTime(1969, 6, 19);
You can do basically the same thing in VB:
Dim dt As New DateTime(1969, 6, 19)
but you can also do this:
Dim dt = #6/19/1969#
When you use a date literal in VB, you ALWAYS use M/dd/yyyy format. It simply couldn't make use of system settings because that would mean that the same code would behave differently on different machines.
Now, when you run a project in the debugger and use the Watch window or the like to view the value of a variable or other expression, the debugger will display a literal value if the type supports it. If the type doesn't support literals, you will see the result of calling ToString
on the object. That means that the debugger will always show you something in M/dd/yyy format for a DateTime
value in a VB project because it's showing you a literal Date
, while what it shows you in a C# project depends on your system settings because it's the result of calling ToString
on a DateTime
.
This is not an issue at all though. The actual value of the DateTime
variables doesn't change. They don't actually contain a format at all. They're just numbers in the system. Format is only an issue when you want to represent the value as text. When you need to do that, you'll call ToString
on your value and that will honour the system settings, whether in VB or C#.
Note that I have used the terms Date
and DateTime
in this answer. DateTime
is a .NET type while Date
is an intrinsic VB data type. Both languages support literals for their intrinsic data types but only VB has an intrinsic data type for dates, which is why only VB supports literal dates. Just as int
in C# and Integer
in VB are aliases for the Int32
type, so Date
in VB is an alias for the DateTime
type, but there is no equivalent in C#.