dwm Posted January 7, 2005 Posted January 7, 2005 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 Quote
pas30339 Posted January 7, 2005 Posted January 7, 2005 (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 January 7, 2005 by pas30339 Quote
dwm Posted January 7, 2005 Author Posted January 7, 2005 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 Quote
pas30339 Posted January 7, 2005 Posted January 7, 2005 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 Quote
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.