Hi,
Im having a bit of difficulty working out how to do the following.
method ( paramType? param1, DateTime? requiredByDate , paramType? param3)
I have a row property which I need to pass to this method, this has a
property of IsNull which is a boolean, so I tried to do the following
method ( param1,
row.IsRequiredByDateNull() ? null, row.RequiredByDate,
param3 )
This fails on compile because it cant cast from a null to a DateTime.
How can i construct this ? 5 1574
Microsoft Newsserver <me@nowhere.comwrote:
Im having a bit of difficulty working out how to do the following.
method ( paramType? param1, DateTime? requiredByDate , paramType? param3)
I have a row property which I need to pass to this method, this has a
property of IsNull which is a boolean, so I tried to do the following
method ( param1,
row.IsRequiredByDateNull() ? null, row.RequiredByDate,
param3 )
This fails on compile because it cant cast from a null to a DateTime.
How can i construct this ?
Don't cast to DateTime - cast to DateTime? (with the question mark).
Then it should be fine.
--
Jon Skeet - <sk***@pobox.com>
Web site: http://www.pobox.com/~skeet
Blog: http://www.msmvps.com/jon_skeet
C# in Depth: http://csharpindepth.com
should have read
row.IsRequiredByDateNull() ? null : row.RequiredByDate;
"Microsoft Newsserver" <me@nowhere.comwrote in message
news:eV**************@TK2MSFTNGP05.phx.gbl...
Hi,
Im having a bit of difficulty working out how to do the following.
method ( paramType? param1, DateTime? requiredByDate , paramType?
param3)
I have a row property which I need to pass to this method, this has a
property of IsNull which is a boolean, so I tried to do the following
method ( param1,
row.IsRequiredByDateNull() ? null, row.RequiredByDate,
param3 )
This fails on compile because it cant cast from a null to a DateTime.
How can i construct this ?
Great thanks Jon
"Jon Skeet [C# MVP]" <sk***@pobox.comwrote in message
news:MP*********************@msnews.microsoft.com. ..
Microsoft Newsserver <me@nowhere.comwrote:
>Im having a bit of difficulty working out how to do the following.
method ( paramType? param1, DateTime? requiredByDate , paramType? param3)
I have a row property which I need to pass to this method, this has a property of IsNull which is a boolean, so I tried to do the following
method ( param1, row.IsRequiredByDateNull() ? null, row.RequiredByDate, param3 )
This fails on compile because it cant cast from a null to a DateTime.
How can i construct this ?
Don't cast to DateTime - cast to DateTime? (with the question mark).
Then it should be fine.
--
Jon Skeet - <sk***@pobox.com>
Web site: http://www.pobox.com/~skeet
Blog: http://www.msmvps.com/jon_skeet
C# in Depth: http://csharpindepth.com
On Jun 23, 5:16 pm, "Microsoft Newsserver" <m...@nowhere.comwrote:
should have read
row.IsRequiredByDateNull() ? null : row.RequiredByDate;
"Microsoft Newsserver" <m...@nowhere.comwrote in message
news:eV**************@TK2MSFTNGP05.phx.gbl...
Hi,
Im having a bit of difficulty working out how to do the following.
method ( paramType? param1, DateTime? requiredByDate , paramType?
param3)
I have a row property which I need to pass to this method, this has a
property of IsNull which is a boolean, so I tried to do the following
method ( param1,
row.IsRequiredByDateNull() ? null, row.RequiredByDate,
param3 )
This fails on compile because it cant cast from a null to a DateTime.
How can i construct this ?
I once had the same problem.
I can't check it with a compiler right now, but the solution is
something like this:
row.IsRequiredByDateNull() ? (DateTime?)null : row.RequiredByDate;
yes, your absolutely correct. In fact Jon Skeet came up with the same
solution. For some reason , I never thought of casting to a nullable type.
DOH!
Thanks for your help.
"Michal Piaskowski" <pi*****@gmail.comwrote in message
news:ac**********************************@d45g2000 hsc.googlegroups.com...
On Jun 23, 5:16 pm, "Microsoft Newsserver" <m...@nowhere.comwrote:
>should have read
row.IsRequiredByDateNull() ? null : row.RequiredByDate;
"Microsoft Newsserver" <m...@nowhere.comwrote in message
news:eV**************@TK2MSFTNGP05.phx.gbl...
Hi,
Im having a bit of difficulty working out how to do the following.
method ( paramType? param1, DateTime? requiredByDate , paramType?
param3)
I have a row property which I need to pass to this method, this has a
property of IsNull which is a boolean, so I tried to do the following
method ( param1,
row.IsRequiredByDateNull() ? null,
row.RequiredByDate,
param3 )
This fails on compile because it cant cast from a null to a DateTime.
How can i construct this ?
I once had the same problem.
I can't check it with a compiler right now, but the solution is
something like this:
row.IsRequiredByDateNull() ? (DateTime?)null : row.RequiredByDate;
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Jacob Jensen |
last post by:
This question has probably been asked a million time, but here it comes
again. I want to learn the difference between the three type cast operators:
static_cast, reinterpret_cast, dynamic_cast. A...
|
by: Marco |
last post by:
I need to get a iterator from any generic collection.
public class .... GetIterator(Object collection)
{
.....
}
|
by: Remco |
last post by:
Hi,
Let me try to simply explain my questions.
I've created a portal site with different types of users, e.g. Portal
Administrators and Normal Users.
One base class SessionUser (has a enum...
|
by: JimM |
last post by:
I am trying to create a method in VS 2003 that validates an object argument
is of the proper type and within a range of values.
I am trying to use a Type to define the casting and object type for...
|
by: g3000 |
last post by:
I have a problem with a Visual Studio 2005 web project.
I have two pages. SelectProject.aspx and ShowProject.aspx
The first page ( SelectProject.aspx) has two drop down lists.
After the user...
|
by: William S Fulton |
last post by:
I'm looking for the name of the following casting style in order to do
some reading around on it and why it is sometimes used.
unsigned long long ull = 0;
void * ptr = 0;
ull = *(unsigned...
|
by: brekehan |
last post by:
I've always been a little sketchy on the differences between static,
dynamic, and reinterpret casting. I am looking to clean up the
following block by using C++ casting instead of the C style...
|
by: Tony Johansson |
last post by:
Hello!
Here I have two different way to use casting.
Is any of these any better then the other?
Or is it just a question of taste.
newCards.Add((Card)sourceCard.Clone());...
|
by: Bill Reid |
last post by:
I just noticed that my "improved" version of sscanf() doesn't assign
floating point numbers properly if the variable assigned to is declared
as a "float" rather than a "double". (This never...
|
by: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
|
by: ryjfgjl |
last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
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
|
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...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
| |