4

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; 
}
  1. is replaced with one derived from the same interface or abstract class is it maybe because IList<> members must share some common object type?
  2. must that common type to have the same name as IList<> type, eg. IList -> derived from T, or IList -> derived from InterfaceT, IT?

Thanks & Regards, Milan.

1
  • 2
    can you please state the question directly, instead of pointing to a question? Commented Aug 29, 2009 at 10:51

1 Answer 1

8

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.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.