I have a method for which the return type is an int with a null value.
private int? LookupId(string name, string stateAbbreviation)
I am trying to clear the code and decided to use a conditional statement in the return statement.
return id != 0 ? id : null;
Basically, if id is not 0, go to the head and return the identifier. It should never return 0 from db. If, by chance, this is 0, return null.
Error: "The type of the conditional expression cannot be determined because there is no implicit conversion between" int "and" "
The conditional op is intended to replace the current If ... Else statement.
Is there something wrong trying to use a conditional expression this way in this combination? What am I missing?
source
share