title: c# generic method overload not consistent with abstract Visitor pattern
body: <p>experimenting with Visitor pattern and generic method I found a kind of discrepancy in C#.NET. AFAIK C# compiler prefers an explicit overload to a generic method, therefore the following code:</p>
  <pre><code>public abstract class A
  {
      public abstract void Accept(Visitor v);
  }
  
  public class B : A
  {
      public override void Accept(Visitor v)
      { v.Visit(this); }
  }
  
  public class C : A
  {
      public override void Accept(Visitor v)
      { v.Visit(this); }
  }
  
  public class D : A
  {
      public override void Accept(Visitor v)
      { v.Visit(this); }
  }
  
  public class Visitor
  {
      public void Visit(B b)
      { Console.WriteLine(&quot;visiting B&quot;); }
  
      public void Visit(C c)
      { Console.WriteLine(&quot;visiting C&quot;); }
  
      public void Visit&lt;T&gt;(T t)
      { Console.WriteLine(&quot;visiting generic type: &quot; + typeof(T).Name); }
  }
  
  class Program
  {
  
      static void Main()
      {
          A b = new B();
          A c = new C();
          A d = new D();
  
          Visitor v = new Visitor();
  
          b.Accept(v);
          c.Accept(v);
          d.Accept(v);
      }
  }
  </code></pre>
  <p>The output produced is (as expected):</p>
  <pre><code>visiting B
  visiting C
  visiting generic type: D
  </code></pre>
  <p>However this Visitor pattern implementation does not allow to exchange the Visitor class. Introducing an abstract class VisitorBase and forwarding the call to the overloads produces smth. unexpected for me....</p>
  <pre><code>public abstract class A
  {
      public abstract void Accept(VisitorBase v);
  }
  
  public class B : A
  {
      public override void Accept(VisitorBase v)
      { v.Visit(this); }
  }
  
  public class C : A
  {
      public override void Accept(VisitorBase v)
      { v.Visit(this); }
  }
  
  public class D : A
  {
      public override void Accept(VisitorBase v)
      { v.Visit(this); }
  }
  
  public abstract class VisitorBase
  {
      public abstract void Visit&lt;T&gt;(T t);
  }
  
  public class Visitor : VisitorBase
  {
      protected void VisitImpl(B b)
      { Console.WriteLine(&quot;visiting B&quot;); }
  
      protected void VisitImpl(C c)
      { Console.WriteLine(&quot;visiting C&quot;); }
  
      protected void VisitImpl&lt;T&gt;(T t)
      { Console.WriteLine(&quot;visiting generic type: &quot; + typeof(T).Name); }
  
      public override void Visit&lt;T&gt;(T t)
      {
          VisitImpl(t); //forward the call to VisitorImpl&lt;T&gt; or its overloads
      }
  }
  
  class Program
  {
  
      static void Main()
      {
          A b = new B();
          A c = new C();
          A d = new D();
  
          VisitorBase v = new Visitor();
  
          b.Accept(v);
          c.Accept(v);
          d.Accept(v);
      }
  }
  </code></pre>
  <p>Now the output is:</p>
  <pre><code>visiting generic type: B
  visiting generic type: C
  visiting generic type: D
  </code></pre>
  <p>Do generic methods only prefer generic methods? Why are no explicit overloads called?</p>