title: c# Addition operator borrowed from implicit conversion to and from some types, but not others?
body: <p>Let's create a class and make it implicitly convertible to and from <code>int</code>:</p>
  
  <pre><code>class Foo
  {
      int val;
      public Foo() { }
      public Foo(int val) =&gt; this.val = val;
      public static implicit operator int(Foo f) =&gt; f.val;
      public static implicit operator Foo(int val) =&gt; new Foo(val);
  }
  </code></pre>
  
  <p>The following code compiles fine: </p>
  
  <pre><code>Foo foo1 = new Foo();
  Foo foo2 = new Foo();
  Foo sum = foo1 + foo2;
  </code></pre>
  
  <p>It simply converts each value to <code>int</code>, performs the addition, and converts back to <code>Foo</code>.</p>
  
  <p>Now let's try using <code>decimal</code> instead of <code>int</code>:</p>
  
  <pre><code>class Foo
  {
      decimal val;
      public Foo() { }
      public Foo(decimal val) =&gt; this.val = val;
      public static implicit operator decimal(Foo f) =&gt; f.val;
      public static implicit operator Foo(decimal val) =&gt; new Foo(val);
  }
  </code></pre>
  
  <p>Again, the code:</p>
  
  <pre><code>Foo sum = foo1 + foo2;
  </code></pre>
  
  <p>works fine.</p>
  
  <p>Now, let's try another struct with the addition operator defined, <code>TimeSpan</code></p>
  
  <pre><code>class Foo
  {
      TimeSpan val;
      public Foo() { }
      public Foo(TimeSpan val) =&gt; this.val = val;
      public static implicit operator TimeSpan(Foo f) =&gt; f.val;
      public static implicit operator Foo(TimeSpan val) =&gt; new Foo(val);
  }
  </code></pre>
  
  <p>Now, when we try </p>
  
  <pre><code>Foo sum = foo1 + foo2;
  </code></pre>
  
  <p>We get a compiler error:</p>
  
  <blockquote>
    <blockquote>
      <p>Error CS0019  Operator '+' cannot be applied to operands of type 'Foo' and 'Foo'</p>
    </blockquote>
  </blockquote>
  
  <p>This seems odd. Both <code>decimal</code> and <code>TimeSpan</code> have overloaded + operators defined: </p>
  
  <p>(from metadata)</p>
  
  <pre><code>public static TimeSpan operator +(TimeSpan t1, TimeSpan t2);
  
  
  public static Decimal operator +(Decimal d1, Decimal d2);
  </code></pre>
  
  <p>Why does this work for some types but not others?</p>