title: C# covariance on generic methods
body: <p>In Java I can easily write:</p>
  
  <pre class="lang-java prettyprint-override"><code>interface A { void foo(); }
  class B implements A { public void foo() {} }
  class C implements A { public void foo() {} }
  
  &lt;T&gt; List&lt;T&gt; combined(Collection&lt;? extends T&gt; a, Collection&lt;? extends T&gt; b) {
      List&lt;T&gt; res = new ArrayList&lt;&gt;();
      res.addAll(a);
      res.addAll(b);
      return res;
  }
  
  public static void main(String[] args) {
      List&lt;A&gt; list = combine(Arrays.asList(new B()), Arrays.asList(new C()));
  }
  </code></pre>
  
  <p>The above code compiles when put inside a class (ignoring modifiers etc).</p>
  
  <p>The goal is to write a function <code>Combine</code> which takes two <code>IEnumerable</code>s of <em>potentially different</em> types A and B which both inherit from some T. The compiler <em>should infer the type of T</em> and return an <code>IEnumerable&lt;T&gt;</code> without me having to explicitly specify any type in the function call.</p>
  
  <p>How would I do this in C#?</p>