C# implicit conversions and == operator

Posted by Arnis L. on Stack Overflow See other posts from Stack Overflow or by Arnis L.
Published on 2009-05-21T09:13:04Z Indexed on 2010/04/10 19:03 UTC
Read the original article Hit count: 123

Some code for context:

class a


class b
    public a a{get;set;}
    public static implicit operator a(b b)
        return b.a;

  a a=null;
  b b=null;
  a = b;

  //compiler: cannot apply operator '==' to operands of type tralala...
  bool c = a == b;

Is it possible to use == operator on different type instances, where one can implicitly convert to another? What did i miss?

If types must be the same calling ==, then why

int a=1;
double b=1;
bool c=a==b;


© Stack Overflow or respective owner

Related posts about c#

Related posts about type-conversion