choice of collection

larrysy
larrysy used Ask the Experts™
on
I need to do the following:
1. put some objects into a collection
2. sort from min to max (with or without a key)
3. get the object with the min value (something like "peek")
4. modify the object without removing it

Key used will be a property of the object.

I don't know the keys or values in advance so I need to be able to use an index to get the top object.

Which is the best collection to use?  

I'm looking at the following:
SortedList(Of K,V)
SortedDictionary(Of K,V)
SortedSet(Of V)
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Glanced up at my screen and thought I had coded the Matrix...  Turns out, I just fell asleep on the keyboard.
Most Valuable Expert 2011
Top Expert 2015
Commented:
I think even a regular List(Of X) would be fine. You could call the Sort method on it when you needed to. I don't think any of the Dictionaries are going to grant you an index-based accessor. I haven't worked with SortedSet, so I can't say whether or not it has index-based accessors. At this point, my suggestion would be the list--either the plain-jane list, or the SortedList. The plain-jane version just needs to have the Sort method called prior to you accessing the first element (i.e. index zero).
Most Valuable Expert 2012
Top Expert 2014
Commented:

Author

Commented:
Hi kaufmed, I tested your suggestion and it works.

Hi CodeCruiser, the article is a little bit more than what I need right now but I might be able to use it later.

Thanks.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial