Re: Decimal nullable problem
- From: Luigi <ciupazNoSpamGrazie@xxxxxxxxx>
- Date: Thu, 25 Sep 2008 02:41:02 -0700
"Jon Skeet [C# MVP]" wrote:
Well, that many conditionals and null-coalescing operators makes the
code very difficult to read for a start. I would break it up into
separate statements - I suspect you'll find the problem goes away then
anyway. I believe the issue is demonstrated by this rather simpler
code:
decimal? foo = true ? 5m : null;
The types of the rightmost two operands are "decimal" and "<null>" and
there's no implicit conversion from either one to the other. If you
cast either of the operands to "decimal?" it will work fine:
decimal? foo = true ? (decimal?) 5m : null;
or
decimal? foo = true ? 5m : (decimal?) null;
You could do the same with your original code - casting the null is
probably simpler than casting the calculation.
Well, thank you Jon, another good point of view to keep in mind.
Luigi
.
- References:
- Decimal nullable problem
- From: Luigi
- Re: Decimal nullable problem
- From: Jon Skeet [C# MVP]
- Decimal nullable problem
- Prev by Date: Re: Decimal nullable problem
- Next by Date: Unicode String in TreeView
- Previous by thread: Re: Decimal nullable problem
- Next by thread: RegularExpresionValidator for date
- Index(es):
Relevant Pages
|