title: C#, Generic Lists and Inheritance
body: <p>I have a class called Foo that defines a list of objects of type A:</p>
  
  <pre><code>class Foo {
      List&lt;A&gt; Items = new List&lt;A&gt;();
  }
  </code></pre>
  
  <p>I have a class called Bar that can save and load lists of objects of type B:</p>
  
  <pre><code>class Bar {
      void Save(List&lt;B&gt; ComplexItems);
      List&lt;B&gt; Load();
  }
  </code></pre>
  
  <p>B is a subclass of A. Foo, Bar, A and B are in a library and the user can create children of any of the classes.</p>
  
  <p>What I would like to do is something like the following:</p>
  
  <pre><code>Foo MyFoo = new Foo();
  Bar MyBar = new Bar();
  
  MyFoo.Items = MyBar.Load();
  MyBar.Save(MyFoo.Items);
  </code></pre>
  
  <p>Obviously this won't work. Is there a clever way to do this that avoids creating intermediate lists?</p>
  
  <p>thanks, Andy</p>