Re: Decimal nullable problem

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



"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
.



Relevant Pages

  • Re: Fun and Mental; Raisin for High; Achievements of Shoes
    ... > duration). ... I suspect talks have already begun, ... casting to begin in a day or two. ...
    (comp.lang.c)
  • Re: Lawful Stupid
    ... >>>I suspect that you're greatly underestimating the gravity of casting an ... >>>aligned spell. ... and nothing Bradd has said suggests otherwise. ... Casting aligned spells is just one way to show a tendency toward ...
    (rec.games.frp.dnd)
  • Re: Rose
    ... Rose, it's whether the producers are interested in having her back? ... I suspect not. ... Casting for Series 4 has probably ended and there is ...
    (uk.media.tv.sf.drwho)