473,396 Members | 2,011 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,396 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 1462
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);
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
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
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
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,...

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.