Home > Articles > Programming > Windows Programming

  • Print
  • + Share This
From the author of

Direct Use of a Generic Container Datatype

As you probably have noticed, the .NET Framework has a rich number of capable container datatypes, including ArrayList, Hashtable, and XML DOM. One option for a data container is to directly use one of those datatypes. In the old days before .NET, this was a pretty common solution because it was so hard to write components in COM that were marshaled by value. Therefore, we most often used disconnected ADO Recordsets or arrays for our data containers.

Using an array is still a possible solution. It's very lightweight and efficient, but it lacks expressiveness and the code isn't very clear—trade-offs all the time.

For the tests of directly using a container datatype, I have chosen to use a Hashtable. You can find a simplified UML diagram in Figure 2, describing the Hashtable.

Figure 2Figure 2 Class model of a Hashtable.

The basic idea of a Hashtable is to store values by keys, making it very efficient to retrieve the values again as long as you know the keys. You use Add() for storing and Item() for retrieving.

A problem with this solution arises when you need to store more than just one collection of rows. For example, I needed to store both the main information about an order and a collection with all the order lines of that specific order. The trick (or hack) I decided to use was to add a factor to the keys for all the order lines. (More about this when we get to the code.)

  • + Share This
  • 🔖 Save To Your Account