A
Andrew McLellan
I think I must be missing something about generics, perhaps just about the
syntax. I'd like to derive a class MyList from System.Collections.Generic so
that it can only contain instance of MyItem.
No problem with
class MyList<T> : List<T>
{
}
but that requires me to create it with MyList <MyItem> myList = new
MyList<MyItem>() and I'd like to hide that bit in the list class itself so I
could call MyList myList = new MyList();
What should the constructor look like? I think it should be something like
the illegal
class MyList : List<T>
{
public MyList() : base (<T>)
{
}
}
but it obviously isn't! Is this possible or is my understanding of generics
completely wrong?
(Anyone know a good primer on this?)
Andrew
syntax. I'd like to derive a class MyList from System.Collections.Generic so
that it can only contain instance of MyItem.
No problem with
class MyList<T> : List<T>
{
}
but that requires me to create it with MyList <MyItem> myList = new
MyList<MyItem>() and I'd like to hide that bit in the list class itself so I
could call MyList myList = new MyList();
What should the constructor look like? I think it should be something like
the illegal
class MyList : List<T>
{
public MyList() : base (<T>)
{
}
}
but it obviously isn't! Is this possible or is my understanding of generics
completely wrong?
(Anyone know a good primer on this?)
Andrew