Compiler Error CS0173
TOC
Collapse the table of content
Expand the table of content
This documentation is archived and is not being maintained.

Compiler Error CS0173

Type of conditional expression can't 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.

The following sample generates CS0173:

// CS0173.cs
// To resolve, mark three of the four conversion routines as explicit
// or remove three of the conversion routines.
public class iii
{
   // a conversion routine
   public static implicit operator a(iii aa)
   {
      return new a();
   }

   // a conversion routine
   public static implicit operator iii(a aa)
   {
      return new iii();
   }

   public static void Main()
   {
      a aa = new a();
      iii ii = new iii();
      a aaa = (1 == 1) ? aa : ii;   // CS0173
   }
}

public class a
{
   // a conversion routine
   public static implicit operator a(iii aa)
   {
      return new a();
   }

   // a conversion routine
   public static implicit operator iii(a aa)
   {
      return new iii();
   }
}
Show:
© 2016 Microsoft