Handling objects of different classes in a derived List<T> class
<p>I have several classes (A, B, C, ...) that all use a <code>List&lt;AnotherClass&gt;</code> to store references to 'other' objects. But 'other' is different for each of the classes A, B, C.
So
Class A contains <code>List&lt;Class_X&gt;</code>
Class B contains <code>List&lt;Class_Y&gt;</code>
Class C contains <code>List&lt;Class_Z&gt;</code></p>

<p>Instead of implementing Add / Delete / Search (etc) functions in A, B, C it seems logical to me to create a class <code>ListRef&lt;T&gt;</code> from <code>List&lt;T&gt;</code></p>

<pre><code>public class ListRef&lt;T&gt;: List&lt;T&gt;
{
    protected ListRef&lt;T&gt; ListOfObjects = null;
    protected string name = null;

    public ListRef&lt;T&gt;
    {
        ListOfObjects = new ListRef&lt;T&gt;();
    }
}
</code></pre>

<p>Using the code above (is this the right code for what I want?) I don't know how I can supply the right class (Class_X, Class_Y, Class_Z) replacing/specifying <code>&lt;T&gt;</code> in the constructor of each class (A, B, C) that will use ListRef.</p>

<p>In the constructor of class A I would like to write something like:</p>

<pre><code>public A() : base&lt;Class_X&gt;
{
}
</code></pre>

<p>How can I specify from WITHIN class A what kind of objects need to be stored in ListOfObjects?</p>

<p>I prefer NOT to write </p>

<pre><code>public A()
{
    ListOfObjects = new ListRef&lt;Class_X();
}
</code></pre>

<p>as I would like to have ListOfObjects declared <strong>private</strong> instead of <strong>protected</strong></p>

<p><hr /></p>

<p>Inside Listref I JUST want to be able to Add, Delete, Search objects. So I'm not actually using those classes (Class_X, Class_Y, Class_Z).</p>

<p>currently I have</p>

<pre><code>public class A
{
     private List&lt;Class_X&gt; ListOfObjects = null;
     A()
     {
         ListOfObjects = new List&lt;Class_X&gt;();
     }

     public void Add(string Name)
     {
        Class_X Object = new Class_X(Name);
        ListOfObjects.Add(Object);
     }
     public void Delete(Class_X Object)
     {
        ListOfObjects.Remove(Object);
     }
}
</code></pre>

<p>and the same kind of code for class B (using Class_Y)   and for class C (using class_Z).
To me it seems logical to use ONE class  ListRef to perform the Add and Delete operations and maintain the list for all classes I use.
(of course the real code is more complicated) </p>
