The type of the argument on the left should be compatible with the type on the right, or vice versa. In other words, there must be an implicit conversion from B
to A
or from A
to B
Type of expression a? b depends on what implicit conversions are available between operand types. In order of preference, type ab is A0, A or B, where A is type a, B is type b (assuming b is of type), and A0 is the base type of A if A is a null type, or otherwise In particular, b is processed as follows:
• If A is not a null type or a reference type, a compile-time error occurs.
• If A is a null type and there is an implicit conversion from b to A0, then the result is A0. At runtime, a is first evaluated. If a is not null, a is expanded to enter A0, and this becomes the result. Otherwise, b is evaluated and converted to type A0, and this becomes the result.
• Otherwise, if there is an implicit conversion from b to A, the result is A. At run time, a is first evaluated. If a is not null, a becomes the result. Otherwise, b is evaluated and converted to type A, and this becomes the result.
• Otherwise, if b is of type B and there is an implicit conversion from A0 to B, then the result is B. At run time, a is first evaluated. If a is not zero, a is expanded to enter A0 (unless A and A0 are the same type) and converted to type B, and this becomes the result. Otherwise, b is evaluated and becomes the result.
• Otherwise, a and b are incompatible, and a compile-time error occurs.