title: Test for List<T>
body: <p>I am trying to test using 'as' keyword but get the null even though the variable I'm trying to test is a collection.</p>
  <pre><code>DoSomething(() =&gt; someMethodReturningCollection()); 
  DoSomething(() =&gt; anotherMethodReturningAnObject());
  
  public void DoSomething(Func&lt;T&gt; aFunc)
  {
     var result = aFunc();
     var test = result as List&lt;T&gt;;
  
     if(test != null){
         DoTaskA();
         return;
     }
  
     //Here `result` is not a collection
     DoTaskB();
  }
  </code></pre>
  <p>The <code>test</code> is always null.  The <code>typeof(T)</code> shows as <code>IEnumerable&lt;T&gt;</code> otherwise.</p>
  <p><strong>I don't think this is a duplicate question</strong>
  I'm trying to test if a type is a collection or not by using the 'as' operator. The issue seems to be the <code>List&lt;T&gt;</code> v. <code>List&lt;string&gt;</code> or <code>List&lt;customer&gt;</code>.  I can successfully test <code>result as List&lt;customer&gt;</code> but not <code>result as List&lt;T&gt;</code>. It seems the <code>as</code> operator expects an explicit type - not a <code>T</code>.</p>