One question on Generic Collection.

microkarl

Regular
Joined
Apr 22, 2004
Messages
88
Location
Morristown, NJ
I am currently using a Hashtable to store a list of collection, its type includes string, integer, and dateTime. After researched a little bit on "Generic", I am very interested of using it. However, from what I know, in order to enforce type safety, the generic collection class has to be defined to allow only one type to be stored. That is, if I initialize a new instance of generic class to be string, I can't use it to store integer. So, in this case, is it better off to just stick with the old fashion Hashtable?

Thanks!
Carl
 
If you require the collection to hold multiple types of items and therefore type safety isn't a concern you may as well stick with a hash table.

If the various objects derive from a common base class or implement the same interface then you could use a generic using the base or interface.

Out of interest is there a reason why you need to store such different objecttypes in the same collection?
 
I am retrieving elements from XML, then have to store these elements into a class as properties. These elements include, ID (integer), Name (string), StartDate (DateTime)...
 
Back
Top