Empty DateTime Value

  • Thread starter Thread starter Picho
  • Start date Start date
P

Picho

Hi all,

Does anyone know of a GOOD explaination why the DateTime type is a value
time (cannot be null) and furthermore does not provide a DateTime.Empty
value?

when using a DateTimePicker control on windows forms, there is the checkbox
that can indicate an empty date value. there is no such thing for the data
type DateTime.

Picho
 
¤ Hi all,
¤
¤ Does anyone know of a GOOD explaination why the DateTime type is a value
¤ time (cannot be null) and furthermore does not provide a DateTime.Empty
¤ value?
¤
¤ when using a DateTimePicker control on windows forms, there is the checkbox
¤ that can indicate an empty date value. there is no such thing for the data
¤ type DateTime.

Because DateTime objects either contain a value or if unassigned are equal to Nothing.


Paul ~~~ (e-mail address removed)
Microsoft MVP (Visual Basic)
 
Paul Clement said:
Because DateTime objects either contain a value or if unassigned
are equal to Nothing.

There's no way a DateTime can be equal to Nothing, because Nothing is a
reference value, and DateTime isn't a reference type. If a DateTime
variable is unassigned, it's simply unassigned and (at least in C#) you
can't use it at all - and I'd hope that's true in other languages. If
it weren't, I'd expect the value to be the same as that of
new DateTime().
 
Jon,
There's no way a DateTime can be equal to Nothing, because Nothing is a
reference value, and DateTime isn't a reference type.

Actually, it can. Nothing, unlike null, is considered equal to the
default value of any type. 0, 0.0, false or null references.



Mattias
 
Mattias Sjögren said:
Actually, it can. Nothing, unlike null, is considered equal to the
default value of any type. 0, 0.0, false or null references.

Blech. I stand corrected and appalled, both at the same time.
 
Picho said:
Does anyone know of a GOOD explaination why the DateTime type is a value
time (cannot be null) and furthermore does not provide a DateTime.Empty
value?

You could make the same argument for int. I imagine the answer lies in the
underlying implemenation of the type as a scalar, which is atomically
manipulated at the processor level.

-- Alan
 
Back
Top