DataTable vs ArrayList with custom Objects

G

George

I am wondering what is the cost of using DataTable.

Lets say i have 1000 Employee records. The object oriented purist will require the Data Layer to return an ArrayList with 1000 Employee objects.

But very often we (at least i) returning DataTable to populate the grid.
But now i am wondering: Am i gaining anything?

The DataTable has to create object DataRow for each row. Versus i am creating Employee object for each row.

So unless DataTable does not create 1000 of objects I am actually loosing the benefits of using strong type and gaining nothing.

Am i correct?

Thanks.
George
 
S

Scott Allen

George:

Your analysis is correct.

The DataTable does provide other features, like the ability to Select
rows and can work in a sorted, filtered, view. As part of a DataSet it
can also persist to an XML file and back again. If these are not
features you need, or are features you have the time to implement, you
still won't be gaining anything.

Some of the code generation tools today do a great job of writing the
code for a custom collection of your business objects. With this
approach you don't lose *any* strong typing (since the ArrayList can
only return object references, which is a bummer, but 2005 will take
care of this someday).
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,819
Latest member
masterdaster

Latest Threads

Top