The compiler will only consider the types of the 2 operands and implicit conversions between them. It will not look for base types or implemented interfaces.
You will need to explicitly cast one of the operands to I
.
From C# language specification:
The second and third operands, x and y, of the ?: operator control the type of the conditional expression.
• If x has type X and y has type Y then
o If an implicit conversion (§6.1) exists from X to Y, but not from Y to X, then Y is the type of the conditional expression.
o If an implicit conversion (§6.1) exists from Y to X, but not from X to Y, then X is the type of the conditional expression.
o Otherwise, no expression type can be determined, and a compile-time error occurs.
If the compiler checked base types too, any combination of types would be valid - in the worse case, the result type would be object
.