Google Groepen ondersteunt geen nieuwe Usenet-berichten of -abonnementen meer. Historische content blijft zichtbaar.

Working with DateTime in .Net

1 weergave
Naar het eerste ongelezen bericht

Johan Burger

ongelezen,
14 jul 2005, 04:55:0214-07-2005
aan
In Delphi for Windows the TDateTime is in essence a numeric field thus
statements such as "myDate := 0;" and "if myDate = 0 then..." are allowed.

I'm trying to achieve something similar with the DateTime object in .Net but
for some reason it's just not behaving the way I would expect it to.
If've tried things like "myDate := convert.ToDateTime(nil);" which worked,
but then if I say "if &Object(myDate) = nil then..." the if translates to a
False where I'm expecting it to be True. I also haven't found any methods
which I can use to set and test for nil. Converting a zero to a DateTime
also raises exceptions.

My question is this: How do I set a date to nothing (either nil or 0) and
secondly, how do I test for the nothing value?

Many thanks


Dirk Andries

ongelezen,
14 jul 2005, 05:58:1714-07-2005
aan
Johan Burger wrote:

1) System.DateTime is a value type. There is no way you can set it to
nothing or nil.
2) You can store it in a variable as System.Object (thus boxed
version). In this case you can assign nil to the variable and test
with Assigned.
3) You can use your own nullable types (or download a .NET Nullables
library somewhere).
Basically a nullable value type is a type which contains a value
(DateTime in your case) and a Boolean property IsNull wich you can test.
Nullables will be available in the .NET 2.0 framework.
4) You could use 'magic values':
System.DateTime.MinValue (default value for a System.DateTime)
System.DateTime.MaxValue

It is a certainly a good idea to get some background on the .NET type
system, especially on Value types, Reference types and System.String
(immutable!).


Kind regards,
Dirk Andries

Johan Burger

ongelezen,
18 jul 2005, 05:18:3118-07-2005
aan
Excellent, thanks!

"Dirk Andries" <nos...@nospam.be> wrote in message
news:42d6...@newsgroups.borland.com...

0 nieuwe berichten