473,394 Members | 1,739 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,394 software developers and data experts.

method should return DateTime but I want it to return null

a get { ... } for public property SelectedValue returns DateTime type to be
used as a parameter in a Sql update query but I'd like it to return "empty"
if no date has been selected...
I cannot use
return null;

because "Cannot convert null to 'System.DateTime' because it is a value
type"

How can this be done?
Jan 31 '06 #1
3 1887
If you're using C# 2 then you can use the Nullable generic type:

public DateTime? SelectedValue
{
get / set;
}

Note the question mark which is short-hand for Nullable<DateTime>. See the
Nullable API doc for more details. If you're using C# 1.0 then you'll need
to either store in a reference type (object) or pick a DateTime to equate to
null (eg. DateTime.MinValue). Alternatively, use an extra bool field to
indicate null.

HTH,
Kent

"Daves" <db****@simnet.is> wrote in message
news:OX**************@TK2MSFTNGP15.phx.gbl...
a get { ... } for public property SelectedValue returns DateTime type to be
used as a parameter in a Sql update query but I'd like it to return "empty"
if no date has been selected...
I cannot use
return null;

because "Cannot convert null to 'System.DateTime' because it is a value
type"

How can this be done?

Jan 31 '06 #2
You can also send the datetime var with out parameter and get the boolean
result like this :

bool Fx(out varDateTime)
{
//return bool;
}
if bool is true, varDateTime is not null

Vivek

Le relais des Artistes (Esvicom - Lieu de Vie, ATBM - Théâtre du Bout des
Mains, DW Home Studio) vous souhaite une très bonne année 2006
http://www.relaisdesartistes.com
"Kent Boogaart" <ke****@internode.on.net> a écrit dans le message de news:
%2****************@TK2MSFTNGP11.phx.gbl...
If you're using C# 2 then you can use the Nullable generic type:

public DateTime? SelectedValue
{
get / set;
}

Note the question mark which is short-hand for Nullable<DateTime>. See the
Nullable API doc for more details. If you're using C# 1.0 then you'll need
to either store in a reference type (object) or pick a DateTime to equate
to null (eg. DateTime.MinValue). Alternatively, use an extra bool field
to indicate null.

HTH,
Kent

"Daves" <db****@simnet.is> wrote in message
news:OX**************@TK2MSFTNGP15.phx.gbl...
a get { ... } for public property SelectedValue returns DateTime type to
be used as a parameter in a Sql update query but I'd like it to return
"empty" if no date has been selected...
I cannot use
return null;

because "Cannot convert null to 'System.DateTime' because it is a value
type"

How can this be done?


Jan 31 '06 #3
thx guys, I think I have c# v2, both of your solutions are great.

"Vivek" <vi**************@msn.com> wrote in message
news:eV**************@TK2MSFTNGP10.phx.gbl...
You can also send the datetime var with out parameter and get the boolean
result like this :

bool Fx(out varDateTime)
{
//return bool;
}
if bool is true, varDateTime is not null

Vivek

Le relais des Artistes (Esvicom - Lieu de Vie, ATBM - Théâtre du Bout des
Mains, DW Home Studio) vous souhaite une très bonne année 2006
http://www.relaisdesartistes.com
"Kent Boogaart" <ke****@internode.on.net> a écrit dans le message de news:
%2****************@TK2MSFTNGP11.phx.gbl...
If you're using C# 2 then you can use the Nullable generic type:

public DateTime? SelectedValue
{
get / set;
}

Note the question mark which is short-hand for Nullable<DateTime>. See
the Nullable API doc for more details. If you're using C# 1.0 then you'll
need to either store in a reference type (object) or pick a DateTime to
equate to null (eg. DateTime.MinValue). Alternatively, use an extra bool
field to indicate null.

HTH,
Kent

"Daves" <db****@simnet.is> wrote in message
news:OX**************@TK2MSFTNGP15.phx.gbl...
a get { ... } for public property SelectedValue returns DateTime type to
be used as a parameter in a Sql update query but I'd like it to return
"empty" if no date has been selected...
I cannot use
return null;

because "Cannot convert null to 'System.DateTime' because it is a value
type"

How can this be done?



Jan 31 '06 #4

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

Similar topics

7
by: Abhishek Srivastava | last post by:
Hello All, I am facing a simple problem. I have a method which accepts two parameters. Both are of type DateTime. However when calling this method there are times when the caller does not...
0
by: John Haigh | last post by:
Should possibly have an "add" method in a PostingObject class in the constructor of PostingObject. will call to add a Posting to the ? Does this make sense? My sense is that a PostingObject needs a...
6
by: Millo | last post by:
Hi I'm trying to call the method Contains in a loop: out of the loop I set the primary key of the dataTable. The method returns true one time at a certani value, but then, when the loop steps...
0
by: Vagabond Software | last post by:
I posted this problem earlier and now have more information. I use the DataTable Select method to get find the most recent "LastModified" date in a table of similarly named files. I then use the...
3
by: Oberon | last post by:
How do I deal with this? I am getting an error for each get in the Game class (see code below). In the simplified example below I have reduced this to just 3 fields, one which can be NULL. I...
0
by: Simple Simon | last post by:
Hi, excuse the long post and plz read on :) My web application needs to upload a .csv & .zip file, as well as, import the .csv into a (Sql2000) table and unzip the .zip file to a directory on...
0
by: ruju00 | last post by:
I am getting an error in Login() method of the following class FtpConnection public class FtpConnection { public class FtpException : Exception { public FtpException(string message) :...
5
by: Anders Borum | last post by:
Hi! While implementing a property manager (that supports key / value pairs), I was wondering how to constrain T to a struct or string type. Basically, I guess what I'm looking for is the common...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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: 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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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...

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.