microkarl Posted February 8, 2008 Posted February 8, 2008 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 Quote Donald DUCK : YOU ARE FIRED!!!
Administrators PlausiblyDamp Posted February 8, 2008 Administrators Posted February 8, 2008 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? Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
microkarl Posted February 8, 2008 Author Posted February 8, 2008 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)... Quote Donald DUCK : YOU ARE FIRED!!!
Machaira Posted February 8, 2008 Posted February 8, 2008 Can you use serialization (assuming you have control over the XML structure)? Quote Here's what I'm up to.
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.