views:

363

answers:

2

Hello, I have a project that I'm working on that requires changing a 'BaseSortedCollection' class to allow duplicates. The class currently implements IEnumerable, IDisposable, ICollection, and ISerializable. The 'BaseSortedCollection' stores Items that have an ItemID (Int64), which is used as the key when accessing the collection. I need to have two identical items (same ItemID) exist in the collection at the same time as well as be able to be retrieved.

We are using the 2.0 framework.

Any suggestions?

Thanks in advance!

A: 

I guess you will have to extend a regular ArrayList, and override the Add-method to call Sort if you need the auto sorting. However, I can't seem to wrap my head around the idea of two items with the same (what should be unique) identification number?!

Edit, or maybe NameValueCollection (in System.Collections.Specialized) is more appropriate? Extend it and add your own sorting method...

Björn
+2  A: 

Each item in your BaseSortedCollection could be a List(T), so if you have two items with the same key, you will have a List(T) containing two items for the entry corresponding to that key.

Meta-Knight