Reputation: 55
Could you please clarify for me the question asked here.
Why it is important that originally defined class:
public class Metadata<DataType> where DataType : struct
{
private DataType mDataType;
}
Thanks & Regards, Milan.
Upvotes: 4
Views: 2482
Reputation: 11074
Each generic type instantiation is a new type. i.e MetaData<int>
is a different type than MetaData<bool>
.
The compiler generates a type like this (inspect using .Net refelector)
Namespace.Metadata`1[[System.Int32, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]]
So you cannot declare a List of heterogeneous types. You can only declare a List of one type. Hence it is necessary to make all generic MetaData<> classes to be inherited from an abstract class or interface.
Upvotes: 8