title: Solving The type arguments for method cannot be inferred from the usage
body: <p>I get this error:
  The type arguments for method '<code>ConsoleApplication1.Program.takeList&lt;T&gt;</code>(<code>System.ComponentModel.BindingList&lt;T&gt;</code>)' cannot be inferred from the usage. Try specifying the type arguments explicitly.</p>
  
  <p>I believe the compiler cannot guess the return type of the chooseList method, but it has to pass it to takeList method. Is there a way to make this work, but not decouple the chooseList method into the Main function??</p>
  
  <pre><code>class Program
  {
      static BindingList&lt;int&gt; listOfInts;
      static BindingList&lt;string&gt; listOfStrings;
      //more lists
  
      static void takeList&lt;T&gt;(BindingList&lt;T&gt; list)
      {
          //do something
          return;
      }
  
      static object chooseList() //instead of object i would put BindingList&lt;T&gt;
      {
          int someCondition = 0;
  
          //code that changes someCondition so compiler doesnt know its value
  
          switch (someCondition)
          {
              case 1: return listOfInts;
  
              //more cases for more lists
  
              default: return listOfStrings;
          }
      }
  
      static void Main(string[] args)
      {
          Program testClass = new Program();
          var chosenList = chooseList();
          takeList(chosenList);
      }
  }
  </code></pre>
  
  <p>EDIT:</p>
  
  <p>Here is an opposite situation which should work. I would like to convert it to the above:</p>
  
  <pre><code>class Program
  {
      static BindingList&lt;int&gt; listOfInts;
      static BindingList&lt;string&gt; listOfStrings;
      //more lists
  
      static void takeList&lt;T&gt;(BindingList&lt;T&gt; list)
      {
          //do something
          return;
      }
  
      static void Main(string[] args)
      {
          Program testClass = new Program();
  
          int someCondition = 0;
  
          //code that changes someCondition so compiler doesnt know its value
  
          switch (someCondition)
          {
              case 1:
                  takeList(listOfInts);
                  break;
  
              //more cases for more lists
  
              default:
                  takeList(listOfStrings);
                  break;
          }
  
          //Instead of the switch here, i would like to write takelist(doTheSwitch(someCondition));
      }
  }
  </code></pre>