Extended Sorted List

C

Cybertof

Hi !

I would like to make an array of structure (collection ?) that would
behave like an advanced sorted list : a sorted list with one key but
with multiple values (sorted lists are key/value items).

- indexed by value index or by key (2 indexers)
- sortable by key or a secondary key
- supporting foreach loops


Is there a class my 'ExtendedList' could inherit from that would make
the most part of the job ?

Any hints to do it ?
Any Example ?


Regards,
Cybertof.
 
N

Nicholas Paldino [.NET/C# MVP]

Cybertof,

It sounds like you want a stongly-typed dictionary. You can extend
DictionaryBase. However, you would have to implement the functionality that
would sort the list based on a field in the value (that field being a public
field or a property). Managing this is going to have a performance impact
as well.

On top of that, you will have to change the enumerator so that it
returns the items in the dictionary in the order you want. Like the
Hashtable, it should return a structure with the key/value pair, and not
just the value.

Hope this helps.
 
C

Cybertof

Nicholas,

What do you mean with
'Managing this is going to have a perfomance impact' ?

Is there a more efficient way ?

What is the restriction you are speaking about when you say
"Like the Hashtable, it should return a structure with the key/value
pair, and not just the value."



Regards,
Cybertof.
 
N

Nicholas Paldino [.NET/C# MVP]

Cybertof,

The reason it will have a performance impact is that in addition to
storing the value, on each add, insert, and removal of an item, you are
going to have to calculate where in the list it belongs, and that takes
time.

If you do a foreach on a Hashtable, you will be returned an instance of
type DictionaryEntry, which has a field for the key, and a field for the
value in the Hashtable. Your object should reflect this as well, instead of
just returning a value.
 
C

Cybertof

Maybe there is something i don't understand, but why should my object
return a (key,value) pair if i already know the key itself (because i
use it during the 'call' to the search through the key indexer) ?

Cybertof.
 

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