C# Compiler Error
CS0173 – Type of conditional expression cannot be determined because there is no implicit conversion between ‘class1’ and ‘class2’
Reason for the Error
You will receive this error when the conditional operator cannot cast implicitly.
For example, try compiling the below code snippet
public class Hello { public static void Main() { int input = 1; object output = (input == 0) ? null : null; return -1; } }
This will result with the error CS0173.
error CS0173: Type of conditional expression cannot be determined because there is no implicit conversion between the parameters.
Solution
To fix this error, ensure that there is one and only one implicit conversion exists between either sides. The above code can be fixed by casting the type to object for both the class1 and class 2 as shown below.
public class Hello { public static void Main() { int input = 1; object output = (input == 0) ? (object)null : (object) null; return -1; } }