I've got a method that whose return type is a nullable int.
private int? LookupId(string name, string stateAbbreviation)
I'm trying to cleanup the code and decided to use a conditional operator on the return statement.
return id != 0 ? id : null;
Basically, if the id is not 0, go a head and return the id. It should never return 0 from the db. If, by chance, it is 0, return null.
The error is "Type of conditional expression cannot be determined because there is no implicit conversion between 'int' and '' "
The conditional op is intended to replace a functioning If...Else statement.
Is there anything wrong with trying to use a conditional this way, in this combination? What am I missing?
int?
, and not anint
.