title: How to create a collection class containing list of abstract elements
body: <p>I need to create a collection to containing a list of abstract segments.</p>
  
  <p>I have a number of derived classes from segment i.e. <code>LineSegment : Segment</code></p>
  
  <pre><code>public class Path : IEnumerable
  {
          private List&lt;Segment&gt; segments = new List&lt;Segment&gt;();
  
  
          public List&lt;Segment&gt; Segments 
          {  
              set { Segments = value;}
              get { return this.segments; } 
          }
          //some code inc ctrs
  
  }
  </code></pre>
  
  <p>I'd like to be able to define <code>LinePath</code> as a derived class from base class <code>Path</code></p>
  
  <pre><code>public class LinePath : Path, IEnumerable
  {        
          public LinePath(List&lt;LineSegment&gt; s)
          {
              this.Segments = s; //error
          }
  }
  </code></pre>
  
  <p>However I keep running into situations where I can't easily edit the contains of a <code>LinePath</code> because of the list it contains still being a <code>Segment</code> list (lots of casting) or when I wish to create a normal <code>Path</code> from a <code>LinePath</code> plus other derived segments.</p>
  
  <p>What would be a standard format for this kind of problem? Maybe I should give up on <code>LinePath</code> and just work with <code>Path</code> objects?</p>
  
  <p>I realise there may be a slight vagueness to this question, I apologise for this but need to get a handle on what actually is causing me confusion and to avoid a messy solution.</p>