Share via


Compiler Error CS0173

Type of conditional expression cannot be determined because there is no implicit conversion between 'class1' and 'class2'

Conversions between classes are useful when you want objects of different classes to work with the same code. However, two classes that will work together cannot have mutual and redundant conversions.

To resolve CS0173, verify that there is one and only one implicit conversion between class1 and class2, regardless of which direction the conversion is in and regardless of which class the conversion is in. For more information, see Implicit Numeric Conversions Table (C# Reference) and Conversion Operators (C# Programming Guide).

Example

The following sample generates CS0173:

// CS0173.cs
public class C {}
public class A {}

public class MyClass
{
   public static void F(bool b)
   {
      A a = new A();
      C c = new C();
      object o = b ? a : c;  // CS0173
   }

   public static void Main()
   {
      F(true);
   }
}

The following code produces CS0173 in Microsoft Visual Studio 2008 but not in Visual Studio 2005.

//cs0173_2.cs
class M
{

static int Main ()
{
              int X = 1;
        object o = (X == 0) ? null : null; //CS0173
        return -1;
}
}