I have it set so I have to use the explicit type for built-in and apparent types, and var
everywhere else:
This works fine for int
and even Guid
but not for DateTime
:
Why does it want to use var
for DateTime
variables instead of the explicit DateTime
type?
As per the docs, DateTime
is not a built in type (see also here).
Only lower case aliases like int
or string
are built in.
Your Guid
example may work because the "type is apparent".
That may explain why:
Guid h = Guid.NewGuid();
Guid i = h;
h
is left alone, but i
is not (since NewGuid
is classed as a creation method).
I believe it doesn't work for DateTime.Now
since it is not a static method (it is a property). But it does work for DateTime.Parse
- for example.