collectionbase vs generic

A

Andreas Zita

Im new to 2.0 and have a question about generic collections.

In 1.1 I used to create custom collections derived from collectionbase. For
instance ItemCollection : CollectionBase. Then I would also have collections
such as MovieCollection or ImageCollection deriving from ItemCollection
where ItemCollection was handling methods such as FindItemById(int id).

In this case converting from a MovieCollection to a ItemCollection was no
problem and could be done implicitly. I could for instance have a base class
Database having a field ItemCollection m_items and then initiating it as a
MovieCollection in a derived MovieDatabase-class.

How is this scenario possible in 2.0 with generics instead of
collectionbase?

I have noticed that ItemCollection<ItemType> m_items =
(ItemCollection<ItemType>)new ItemCollection<MovieType> is not possible even
though Movie inherits from Item.

Should I stick to collectionbase in this case?

/Andreas Zita
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top