title: Generic method to return instance of child class in List of parent classes
body: <p>I'm trying to do something but I don't know how to call/name this and I can't find anything usefull on Google. I have base class</p>
  
  <pre><code>public class Parent{/*some code here*/}
  </code></pre>
  
  <p>and child classes</p>
  
  <pre><code>public class Child1:Parent{/*more code*/}
  public class Child2:Parent{/*expended behaviour*/}
  </code></pre>
  
  <p>If I create </p>
  
  <pre><code>List&lt;Parent&gt; children = new List&lt;Parent&gt;();
  </code></pre>
  
  <p>I can happily put all children in that list but I have trouble writing generic method for retrieving them. Something like this:</p>
  
  <pre><code>public T GetChild&lt;T&gt;()
  {
      var child = children.Find(c =&gt; c.GetType() == typeof(T));
      if (child == null)
          return default(T);
      return child;
  }
  </code></pre>
  
  <p>Compiler complains at last line and if I try to cast <code>child</code> to <code>T</code> explicitely, it complains some more. What shall I do, please advise.</p>