title: C# generic interface specialization
body: <p>I wonder if it is in any way possible to specialize generic interface methods somehow in C#? I have found similar questions, but nothing exactly like this. Now I suspect that the answer is "No, you can't" but I would like to have it confirmed.</p>
  
  <p>What I have is something like the following.</p>
  
  <pre><code>public interface IStorage
  {
      void Store&lt;T&gt;(T data);
  }
  
  public class Storage : IStorage
  {
      public void Store&lt;T&gt;(T data)
      {
          Console.WriteLine("Generic");
      }
  
      public void Store(int data)
      {
          Console.WriteLine("Specific");
      }
  }
  
  class Program
  {
      static void Main(string[] args)
      {
          IStorage i = new Storage();
          i.Store("somestring"); // Prints Generic
          i.Store(1); // Prints Generic
          Storage s = (Storage)i;
          s.Store("somestring"); // Prints Generic
          s.Store(1); // Prints Specific
      }
  }
  </code></pre>
  
  <p>Is there any way to make it use the specialized version of Store when called through the interface? And if not, does anyone know the exact reason why C# treats Generic arguments this way?</p>
  
  <p>Edit:
  The issue could be worked around if it wasn't so that C# cannot resolve template arguments in more than one step.</p>
  
  <pre><code>void Foo&lt;T&gt;(T t)
  {
      SubFoo(t);
  }
  
  void SubFoo&lt;T&gt;(T t)
  {
      Console.WriteLine("Generic");
  }
  
  void SubFoo(int t)
  {
      Console.WriteLine("Specific");
  }
  </code></pre>
  
  <p>A call to Foo(1) here will print "Generic" as well, shouldn't the compiler be able to resolve this? Or does the JIT prevent this?</p>