Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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

Donald DUCK : YOU ARE FIRED!!!
  • Administrators
Posted

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?

Posting Guidelines FAQ Post Formatting

 

Intellectuals solve problems; geniuses prevent them.

-- Albert Einstein

Posted
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)...
Donald DUCK : YOU ARE FIRED!!!

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...