Re: Nullable Convert ? : operand problem



As far as the ternary is concerned, it's two values are incompatible,
since "null" is interpreted as a null object, not the int? missing
value. You can re-educate it with a cast:

int? intVar = decVar == null ? (int?) null :
Convert.ToInt32(decVar.GetValueOrDefault());

Marc
.



Relevant Pages

  • Re: How to print out
    ... an int once again but I doubt this will fix it. ... Sorry, but "try a cast, but I doubt that it will fix it" is bad advice. ... tell the compiler, "I know what I'm doing; ... We're missing some context. ...
    (comp.lang.c)
  • Re: caste Q
    ... int mainis better style, ... Provide prototypes for your ... Missing (NULL, and IIRC also a missing prototype for 'time'. ... Lose the spurious cast. ...
    (comp.lang.c)
  • Re: short res = shortA + shortB result in compiler error. Why?
    ... Cannot implicitly convert type 'int' to 'short'. ... An explicit conversion ... exists (are you missing a cast?) ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: short res = shortA + shortB result in compiler error. Why?
    ... Cannot implicitly convert type 'int' to 'short'. ... An explicit conversion ... exists (are you missing a cast?) ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Nullable Convert ? : operand problem
    ... since "null" is interpreted as a null object, ... You can re-educate it with a cast: ... Furthermore (and to eliminate precedence confusion), ...
    (microsoft.public.dotnet.languages.csharp)