I believe that your collection will have one MyClass type (since T must be the same), because the compiler will not know what types you added to which elements in the collection.
In other words, if you must add 2 items to the list:
list.Add(new MyClass<string>()); list.Add(new MyClass<int>());
then try to reference one:
var myItem = list[1];
The compiler does not know which generic name was assigned to the MyClass list in element 1 , because the elements are added at run time, but the generics are determined at compile time.
I am sure that what you want to do cannot be done.
If you know in advance the number of elements, maybe you can use Tuple ?
Codingwithspike
source share