title: Using List<T> in C# (Generics)
body: <p>That's a pretty elementary question, but I have never delved into generics before and I found myself in the need to use it. Unfortunately I don't have the time right now to go through any tutorials and the answers I found to related questions so far aren't what one could call basic, so there we go:</p>
  
  <p>Let's say I have the following:</p>
  
  <pre><code>List&lt;MyClass1&gt; list1 = getListType1();
  List&lt;MyClass2&gt; list2 = getListType2();
  
  if (someCondition)
      MyMethod(list1);
  else
      MyMethod(list2);
  </code></pre>
  
  <p>And of course</p>
  
  <pre><code>void MyMethod(List&lt;T&gt; list){
      //Do stuff
  }
  </code></pre>
  
  <p>Well, I thought it would be this simple, but apparently it is not. VS warns me that </p>
  
  <blockquote>
    <p>The type arguments for method MyMethod(System.Collections.Generic.List) cannot be inferred from the usage</p>
  </blockquote>
  
  <p>and if I compile it anyway, I get a </p>
  
  <blockquote>
    <p>The type or namespace name 'T' could not be found</p>
  </blockquote>
  
  <p>error. </p>
  
  <p>In the many answers I found, I read that I have to declare what <code>T</code> is, which makes sense, but I couldn't quite grasp how to do so in such a simplistic scenario. Of course, those answers created even more questions in my mind, but right now I just want an explanation of what I'm doing wrong (besides not studying generics) and how to make it right.</p>