By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
460,028 Members | 1,026 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 460,028 IT Pros & Developers. It's quick & easy.

Extended Sorted List

P: n/a
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.
Nov 15 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
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.
--
- Nicholas Paldino [.NET/C# MVP]
- nick(dot)paldino=at=exisconsulting<dot>com

"Cybertof" <cy****************@gmx.net> wrote in message
news:MP************************@msnews.microsoft.c om...
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.

Nov 15 '05 #2

P: n/a
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.

In article <#K*************@tk2msftngp13.phx.gbl>,
ni**************@exisconsulting.com says...
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.

Nov 15 '05 #3

P: n/a
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.
--
- Nicholas Paldino [.NET/C# MVP]
- nick(dot)paldino=at=exisconsulting<dot>com
"Cybertof" <cy****************@gmx.net> wrote in message
news:MP************************@msnews.microsoft.c om...
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.

In article <#K*************@tk2msftngp13.phx.gbl>,
ni**************@exisconsulting.com says...
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.

Nov 15 '05 #4

P: n/a
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.
In article <ey**************@TK2MSFTNGP11.phx.gbl>,
ni**************@exisconsulting.com says...
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.

Nov 15 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.