views:

44

answers:

1

Hello,

I have a number of custom objects of type X. X has a number of parameters and must be unique in the collection. (I created my own equals method based on the custom parameters to examine this) In each object of type x, I have a list of objects y. I want to add/remove/modify easily an object y.

For example:

To write the add method, it would be something like add(objTypeX, objTypeY) I would check or the collections already has a objTypeX. If so: i would add the objTypeY to the already existing objTypeX else: i would create objTypeX and add objTypeY to this object.

To modify an objTypeY, it would be something like(objTypeX, objTypeY, newobjTypeY) I would get objTypeX out of the collections and modify objTypeY to newobjTypeY

Which collections should I use? I tried with hashset but i can get a specific object out of the list, without run down the list till I find that object.

I develop this in vb.net 3.5

+2  A: 

For efficient lookup you should override GetHashCode() with a hash that takes the unique parameters into account; then you can either use a Dictionary<X, IList<Y>> (sorry, don't know the VB syntax for generics...) or, if X handles its own collection of Y, simply use a HashSet<X>.

Tomer Gabel
Thx,But how can I call the object then in the HashSet? Which method should I use?
Masna
I changed back to dictionary, thx.
Masna