title: c# generic inheritance base class to child class
body: <p>I have the following Base class:  </p>
  
  <pre><code>public abstract class BaseClass&lt;T&gt;  where T : IComparable
  {
  
  }
  </code></pre>
  
  <p>and this child class :</p>
  
  <pre><code>public class ChildClass&lt;T&gt; : BaseClass&lt;int&gt;
  {
  
  }
  </code></pre>
  
  <p>from a diffrent place on the program i have the following code:</p>
  
  <pre><code>  List&lt;BaseClass&lt;IComparable&gt;&gt; objectList= new List&lt;BaseClass&lt;IComparable&gt;&gt;();
    ChildClass&lt;int&gt; childObject= new ChildClass&lt;int&gt;();
    ChildClass&lt;double&gt; childObject2= new ChildClass&lt;double&gt;()
    //both int and double are IComparable
  
  
  //the bellow code dosent compile, it syas it cannot be casted, i dont understand why becuse they are his child class:
    objectList.Add(childObject);
    objectList.Add(childObject2); 
  </code></pre>