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

Collection of custom entities

P: n/a
what is the best way to implement collection
of custom entities?
Jul 19 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a

If your "entities" are objects, just create an ArrayList and put them in
there..

ArrayList entities = new ArrayList();
entites.Add(my_entity);
Jul 19 '05 #2

P: n/a
In general, a strongly-typed class is the way to go. The
only things you really need to be aware of are the
following:
The arraylist has less overhead, however it is much less
flexible. It can also be used as a datasource. But, it
can be referenced by index only.

The CollectionBase is flexible, can be used as a
datasource and can be accessed by Index. It is very fast
when accessing by Index. The only major drawback is that
you can't access items by Key. To do this you can do what
I do which is to create an Item(Key as string) method
which can loop through the collection looking for
your "Key" value in the objects. You can also extend it
to return the collection in a sorted order.

The DictionaryBase is the other major option. This is a
name/value collection and the items can only be accessed
by key. The collection cannot be used as a datasource and
you must use a for..each loop to look through everything.
In general, if you don't know the key then this is a bad
type of collection to use. Also, the order the data is
returned is not necessarily the order they were added in.

The choice is pretty wide open, but I'm a big fan of the
collectionbase and extending it. However the choice will
depend on the type of project and the tradeoffs you want
to make.

Jeff Levinson

Author of "Building Client/Server Applications with
VB.NET: An Example Driven Approach"

-----Original Message-----
My entities are objects. And I think ArrayList is very
good and simple solution. My concern is regarding type-
safety. As I understand Microsoft encourages developer touse strong-typed classes. It also eliminates late bindingissue. To solve my problem, I wanted to create a custom
collection (inherited form CollectionBase, for example)
for each business entity. I don't know if I'm doing a
right thing.
-----Original Message-----

If your "entities" are objects, just create an
ArrayListand put them in
there..

ArrayList entities = new ArrayList();
entites.Add(my_entity);
.

.

Jul 19 '05 #3

P: n/a
My entities are objects. And I think ArrayList is very
good and simple solution. My concern is regarding type-
safety. As I understand Microsoft encourages developer to
use strong-typed classes. It also eliminates late binding
issue. To solve my problem, I wanted to create a custom
collection (inherited form CollectionBase, for example)
for each business entity. I don't know if I'm doing a
right thing.
-----Original Message-----

If your "entities" are objects, just create an ArrayList and put them inthere..

ArrayList entities = new ArrayList();
entites.Add(my_entity);
.

Jul 19 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.