GS wrote:
> Hi,
>
> I have following value which I need to check wether it's null or not.
> Issue is that StartPrice itself can be a null and checking
> (myItem.StartPrice.Value == null) do not produce true.
> How do I check for null in this kind of case. I don't want to check
> StartPrice for null and then Value for null again as one option. I just
> want to check Value for null.
>
> Thanks,
> Greg
>
Just do this:
if ((null == myItem.StartPrice) || (null == myItem.StartPrice.Value))
{
// Either .StartPrice or .Value is null, handle that here
}
else
{
// Do stuff with .Value
}
The second test is never evaluated if the first test is true (it's
"short-circuited"), so you won't get an exception. Keep in mind that you
might need to use a different test on the .Value check if .Value is an
int or a string.
Hope this helps,
Luke
|