Export (0) Print
Expand All
Expand Minimize
0 out of 2 rated this helpful - Rate this topic

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();
   }
}
Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft. All rights reserved.