title: Storing a list of different generic types in a class
body: <p><a href="https://i.stack.imgur.com/NmbLL.png" rel="noreferrer"><img src="https://i.stack.imgur.com/NmbLL.png" alt="Class structure"></a></p>
  
  <p>I've attached a picture of what I'm trying to do. Let's say I have a list of T in a class</p>
  
  <pre><code>public class MyClass&lt;T&gt; 
      where T : IMyInterface
  {
      public List&lt;T&gt; list = new List&lt;T&gt;;
  }
  </code></pre>
  
  <p>Now, another class has a list of MyClass.</p>
  
  <pre><code>public class AnotherClass
  {
      public List&lt;MyClass&lt;IMyInterface&gt;&gt; list = new List&lt;MyClass&lt;IMyInterface&gt;&gt;;
  }
  </code></pre>
  
  <p>What is the T that I should put for MyClass? If I put T, then it assumes all types in that class are the same, but it isn't. If I put IMyInterface, I couldn't cast IMyInterface to T when accessing these classes. </p>
  
  <pre><code>new AnotherClass().list.Add(new MyClass&lt;T&gt;()); 
  </code></pre>
  
  <p>What is the type here right now? The list in AnotherClass generic type is IMyInterface but the thing I want to add in is T, which T I want to be dynamic but they are still under IMyInterface.</p>