473,414 Members | 1,757 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,414 software developers and data experts.

Null

Hello, If you have a method which test field to see if it is a valid date
and either returns a DateTime value which either has a valid datetime or it
has null, how can you test if the value returned is null? I tried and I
get an compile error "Can not be applied to operands System.DateTime and
null?

dtStart != null

I also tried the is operator

dtStart is null

but it does not like this either...

Thanks in advance for your assistance!!!!!!!!!!
Nov 15 '05 #1
5 1463
DateTime is a value type :-(
In that sense, it cannot be set to null.
The easiest solution is to define a particular date that will act as a null
(eg: minval)

I remember reading a post about this refering a site where you can download
a class implementing DateTime feature.

José

"Jim Heavey" <Ji*******@nospam.com> a écrit dans le message de
news:Xn*********************************@207.46.24 8.16...
Hello, If you have a method which test field to see if it is a valid date
and either returns a DateTime value which either has a valid datetime or it has null, how can you test if the value returned is null? I tried and I
get an compile error "Can not be applied to operands System.DateTime and
null?

dtStart != null

I also tried the is operator

dtStart is null

but it does not like this either...

Thanks in advance for your assistance!!!!!!!!!!

Nov 15 '05 #2
I figured this one out...
Nov 15 '05 #3
JR
Hi,

It doesn't work because DateTime is a structure which in C# is a value type
not a reference type so assigning null to it has no meaning. It's the same
as doing;

int x;
if(x != null) ;

John.
"Jim Heavey" <Ji*******@nospam.com> wrote in message
news:Xn*********************************@207.46.24 8.16...
Hello, If you have a method which test field to see if it is a valid date
and either returns a DateTime value which either has a valid datetime or it has null, how can you test if the value returned is null? I tried and I
get an compile error "Can not be applied to operands System.DateTime and
null?

dtStart != null

I also tried the is operator

dtStart is null

but it does not like this either...

Thanks in advance for your assistance!!!!!!!!!!

Nov 15 '05 #4
you cannot use null with DateTime but you can do

if (dtStart==DateTime.Empty())

not tested but my guess :)

--
cody

[Freeware, Games and Humor]
www.deutronium.de.vu || www.deutronium.tk
Nov 15 '05 #5
codymanix <do*********************@gmx.de> wrote:
you cannot use null with DateTime but you can do

if (dtStart==DateTime.Empty())

not tested but my guess :)


There *is* no DateTime.Empty() method.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 15 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

26
by: Agoston Bejo | last post by:
I want to enforce such a constraint on a column that would ensure that the values be all unique, but this wouldn't apply to NULL values. (I.e. there may be more than one NULL value in the column.)...
3
by: iStrain | last post by:
Hiya. I'm _sure_ this is an FAQ, but Googling hasn't produced the answer in a way I can make sense out of. I know I should get this, but so far no way... I'm creating tables and doing queries in...
5
by: Mike MacSween | last post by:
This as the row source for a combo: SELECT qryRole.RoleID, qryRole.Role FROM qryRole WHERE (((qryRole.RoleID) Not In (SELECT RoleID FROM qryRoleEvent INNER JOIN qryEvent ON qryRoleEvent.EventID...
3
by: sathyashrayan | last post by:
The standard confirms that the following initialization of a struct struct node { --- --- } struct node var = {NULL};
102
by: junky_fellow | last post by:
Can 0x0 be a valid virtual address in the address space of an application ? If it is valid, then the location pointed by a NULL pointer is also valid and application should not receive "SIGSEGV"...
29
by: Jason Curl | last post by:
I've been reading this newsgroup for some time and now I am thoroughly confused over what NULL means. I've read a NULL pointer is zero (or zero typecast as a void pointer), others say it's...
5
by: David Sworder | last post by:
Hi, I've created a UserControl-derived class called MyUserControl that is able to persist and subsequently reload its state. It exposes two methods as follows: public void Serialize(Stream...
64
by: yossi.kreinin | last post by:
Hi! There is a system where 0x0 is a valid address, but 0xffffffff isn't. How can null pointers be treated by a compiler (besides the typical "solution" of still using 0x0 for "null")? -...
0
by: Aaron Morton | last post by:
I'm working on a IHttpModule that handles the PreSendRequestHeaders event from the HttpApplication, if the event is raised after EndRequest then HttpContext.Current is null. If it is raised before...
46
by: lovecreatesbea... | last post by:
Do you prefer malloc or calloc? p = malloc(size); Which of the following two is right to get same storage same as the above call? p = calloc(1, size); p = calloc(size, 1);
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.