Link to home
Start Free TrialLog in
Avatar of eventprostrategies
eventprostrategies

asked on

Help with .NET Collections

My .NET collections usually look something like ...

Public Class DogCollection
    Inherits System.Collections.CollectionBase

with typed Add/Remove/Item/Contains methods.

----

I would like to start creating more versatile collections.

I'd like to be able to ...

>> Access values by index or a string key
>> Custom sorting (not just by key)
>> dim dog1 as dog = dogCollection1("Murphy") or dogCollection1(0) ... how do you make make default methods like these?  for ex, the ListView has an items collection, the ListViewItems of which can be accessed by listView1.Items(displayIndex as integer) instead of listView1.Items.Item(displayIndex as integer) - it's a nifty shortcut, especially for collections.

----

I'll distrubute points fairly to whoever helps out -- links to good examples are appreciated, too.  Just don't post a link to MSDN's System.Collections page or something and expect points.  Crazy kids :P

Thanks in advance!
ASKER CERTIFIED SOLUTION
Avatar of Alexandre Simões
Alexandre Simões
Flag of Switzerland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I forgot the Compare code... but as I gave you a generic item, you must make the comparisson code for each item type you need, and return:
-1 if x<y
0 if x=y
1 if x>y

Alex :p
Avatar of eventprostrategies
eventprostrategies

ASKER

i answered my own question re: howto make "Default" collection methods for the "item" property of a collection here:

https://www.experts-exchange.com/questions/21486373/Implement-Default-Class-Method.html

no one really answered howto implement a collection using both an integer indexer and string key for accessing items ... most efficiently.  I thank alex for some super basic sorting ... this question's dead tho.  i'll award some pts to alex -- cleanup, PAQ this puppy.
An interesting complete example of a custom collection implementation can be found here: http://advancedcollections.codeplex.com

Cheers