Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

Good morning,

 

I am using a SortedList to hold some user-defined types sorted by a key. However, the key might not necessarily be unique, and whenever I try to add an item with a key that already exists in the SortedList, I get an error. I am wondering if there is any way to make the SortedList handle more than one of the same key and just put them "next to each other" (i.e. 1,2,3,3,3,4,5...).

 

Thanks in advance,

dwm

Posted (edited)
Good morning,

 

I am using a SortedList to hold some user-defined types sorted by a key. However, the key might not necessarily be unique, and whenever I try to add an item with a key that already exists in the SortedList, I get an error. I am wondering if there is any way to make the SortedList handle more than one of the same key and just put them "next to each other" (i.e. 1,2,3,3,3,4,5...).

 

Thanks in advance,

dwm

 

SortedList does not support duplicate keys::MSDN

 

If you can use strings then a NameValueCollection will work. It is a 1 to Many collection. MSDN

Edited by pas30339
Posted

Thanks for the reply. I just read up on the NameValueCollection, and the only problem I see is that the object must be a String as well as the key. But looking through the descriptions, it looks like a NameObjectCollectionBase would work for what I'm trying to do. Does that sound correct to you? Does the NameObjectCollectionBase allow a 1-to-many relationship using objects?

 

Thanks again,

dwm

Posted
Thanks for the reply. I just read up on the NameValueCollection, and the only problem I see is that the object must be a String as well as the key. But looking through the descriptions, it looks like a NameObjectCollectionBase would work for what I'm trying to do. Does that sound correct to you? Does the NameObjectCollectionBase allow a 1-to-many relationship using objects?

 

Thanks again,

dwm

 

The abstract class NameObjectCollectionBase would allow you to create your own implementation.

The key would be strings and the values objects. Reference

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...