title: How to treat a dictionary of subclasses as a dictionary of the base class
body: <p>In C# I have a bunch of objects all inheriting from the same base class.<br>
  I also have a number of Dictionaries, one for each subclass.<br>
  What I want to do is add all of those Dictionaries to one <i>List</i> so I can loop through them all and do some work (like comparing the lists etc).  </p>
  
  <p><strong>In summary</strong></p>
  
  <pre><code>Dictionary&lt;string, Child&gt; childObjects = new Dictionary&lt;string, Child&gt;();
  List&lt;Dictionary&lt;string, Parent&gt;&gt; listOfDictionaries = new List&lt;Dictionary&lt;string, Parent&gt;&gt;();
  listOfDictionaries.Add(childObjects);
  </code></pre>
  
  <p>I would have thought that since Child inherits from Parent, this should work, but it won't compile. Clearly I am not understanding something about inheritance and generics :)</p>
  
  <p><strong>A full code example</strong></p>
  
  <pre><code>class Program
  {
      static void Main(string[] args)
      {
          //Creating a Dictionary with a child object in it
          Dictionary&lt;string, Child&gt; childObjects = new Dictionary&lt;string, Child&gt;();
          var child = new Child();
          childObjects.Add(child.id, child);
  
          //Creating a "parent" Dictionary with a parent and a child object in it
          Dictionary&lt;string, Parent&gt; parentObjects = new Dictionary&lt;string, Parent&gt;();
          parentObjects.Add(child.id, child);
          var parent = new Parent();
          parentObjects.Add(parent.id, parent);
  
          //Adding both dictionaries to a general list
          List&lt;Dictionary&lt;string, Parent&gt;&gt; listOfDictionaries = new List&lt;Dictionary&lt;string, Parent&gt;&gt;();
  
          listOfDictionaries.Add(childObjects);  //This line won't compile
  
          listOfDictionaries.Add(parentObjects);
  
  
      }
  }
  
  class Parent
  {
      public string id { get; set; }
      public Parent()
      {
          this.id = "1";
      }
  }
  
  class Child : Parent
  {
      public Child()
      {
          this.id = "2";
      }
  
  }
  </code></pre>
  
  <p>Is there any way of achieving this?</p>