Erwin Pombett
asked on
is it possible to change from DateTime? to DateTime?
hello experts,
i have a method where values can be null, the params are DateTime?
inside my method, I call another method with DateTime values that i check first if they are not null,
the inner method has not DateTime? params,
how can i change from "DateTime?" to "DateTime" ?
i have a method where values can be null, the params are DateTime?
inside my method, I call another method with DateTime values that i check first if they are not null,
the inner method has not DateTime? params,
how can i change from "DateTime?" to "DateTime" ?
ASKER
thank you for your answer,
i didnot succed with your help,
here's the situation.
i have an object drain wich contain the following getter:
OBJET DRAIN
public DateTime? DrainDate
{
set { DrainDate_ = value ; }
get
{
return ((DrainDate_ != null)? DrainDate_ : DateTime.MinValue);
}
}
when i try to get the value i receive the error : cannot convert from nullable datetime to target datetime.
foreach (Drain currentDrain in _Drains)
{
DateTime _currentDrainDate = currentDrain.DrainDate;
this last line refuses to accept my value.
any idea, on how to do it?
i didnot succed with your help,
here's the situation.
i have an object drain wich contain the following getter:
OBJET DRAIN
public DateTime? DrainDate
{
set { DrainDate_ = value ; }
get
{
return ((DrainDate_ != null)? DrainDate_ : DateTime.MinValue);
}
}
when i try to get the value i receive the error : cannot convert from nullable datetime to target datetime.
foreach (Drain currentDrain in _Drains)
{
DateTime _currentDrainDate = currentDrain.DrainDate;
this last line refuses to accept my value.
any idea, on how to do it?
ASKER
ok, i could change the line like this:
foreach (Drain currentDrain in _Drains)
{
DateTime? _currentDrainDate = currentDrain.DrainDate;
and it will pass,
the problem is that i use _currentDrainDate later on my inner method,
and the method i give it to , is not declare with a parameter of type "DateTime?" but "DateTime"
foreach (Drain currentDrain in _Drains)
{
DateTime? _currentDrainDate = currentDrain.DrainDate;
and it will pass,
the problem is that i use _currentDrainDate later on my inner method,
and the method i give it to , is not declare with a parameter of type "DateTime?" but "DateTime"
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
thank you very much,
i didnt think about trying that,
i try several things but not that cast,
"IT DID IT" , as we say in french switzerland ;o)
best regards.
i didnt think about trying that,
i try several things but not that cast,
"IT DID IT" , as we say in french switzerland ;o)
best regards.
One way is to pass in DateTime.MinValue:
if (dateTime == null)
InnerMethod(DateTime.MinVa
Another way is to skip calling InnerMethod altogether if DateTime is null:
if (dateTime != null)
InnerMethod(dateTime);