Use a DataTable in place of a HashTable

E

_eee_

I have been using a HashTable to store name/value pairs, but now I
need to add a third element (name/value/flag). I still need to be
able to index by ["Name"], and I'd like to keep lookup speed as high
as possible.

I'm considering using a DataTable instead of the HashTable since I
have to store the values to a database eventually anyway. It seems
like the DataTable can do what the HashTable is doing in this case,
but I'm concerned about efficiency.

Does anyone happen to know the tradeoffs in using the DataTable
instead? I was originally considering building both tables at the
same time, but that seems unnecessary.
 
M

Miha Markic [MVP C#]

Hi,

You might create a custom value class that encapsulates value and flag?
Using a DataTable seems a bit of an overkill to me.
 
E

_eee_

_eee_ said:
I have been using a HashTable to store name/value pairs, but now I
need to add a third element (name/value/flag). I still need to be
able to index by ["Name"], and I'd like to keep lookup speed as high
as possible.

I'm considering using a DataTable instead of the HashTable since I
have to store the values to a database eventually anyway.


You might create a custom value class that encapsulates value and flag?
Using a DataTable seems a bit of an overkill to me.

Hi Miha,

You mean slow runtime? I could live with the increased code
complexity of the DataTable as long as it doesn't slow runtime down to
a crawl.
 
M

Miha Markic [MVP C#]

Yes, I mean that DataTable has overheads.
Rather use the "holder" class approach.

--
Miha Markic [MVP C#] - RightHand .NET consulting & software development
miha at rthand com
www.rthand.com

_eee_ said:
_eee_ said:
I have been using a HashTable to store name/value pairs, but now I
need to add a third element (name/value/flag). I still need to be
able to index by ["Name"], and I'd like to keep lookup speed as high
as possible.

I'm considering using a DataTable instead of the HashTable since I
have to store the values to a database eventually anyway.


You might create a custom value class that encapsulates value and flag?
Using a DataTable seems a bit of an overkill to me.

Hi Miha,

You mean slow runtime? I could live with the increased code
complexity of the DataTable as long as it doesn't slow runtime down to
a crawl.
 

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

Top