473,383 Members | 1,859 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,383 software developers and data experts.

SortedList doesn't work for this case! Help!

Would someone know why SortedList doesn't work for these two keys?

[ArgumentException: Item has already been added. Key in dictionary:
"xyzbf8d7a21-d4c2-46a7-b005-a15d6ea3a20f" Key being added:
"xyz9097aa36-a64b-406b-8b27-33b42f4890b6"]
System.Collections.SortedList.Add(Object key, Object value) +221

My code looks something like below, the Guid.NewGuid().ToString() is
appended to make sure the key is unique in case of duplicated data.

foreach( CRecord rec in m_sortedList.Values )
{
tmplist.Add( rec.DataRow[fieldName].ToString() +
Guid.NewGuid().ToString(), rec );
}
Nov 15 '05 #1
2 2740
Zeng <zz*@nonospam.com> wrote:
Would someone know why SortedList doesn't work for these two keys?

[ArgumentException: Item has already been added. Key in dictionary:
"xyzbf8d7a21-d4c2-46a7-b005-a15d6ea3a20f" Key being added:
"xyz9097aa36-a64b-406b-8b27-33b42f4890b6"]
System.Collections.SortedList.Add(Object key, Object value) +221

My code looks something like below, the Guid.NewGuid().ToString() is
appended to make sure the key is unique in case of duplicated data.

foreach( CRecord rec in m_sortedList.Values )
{
tmplist.Add( rec.DataRow[fieldName].ToString() +
Guid.NewGuid().ToString(), rec );
}


Looks odd to me. Could you write a short but complete program which
demonstrates the problem? Are you using a specific IComparer which
might be comparing those keys and saying they're equal?

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 15 '05 #2
You were right. The comparer I used said they were equal. I didn't realize
that SortedList used the comparer to determine the uniqueness of the key.
Thank you very much.

"Jon Skeet" <sk***@pobox.com> wrote in message
news:MP************************@news.microsoft.com ...
Zeng <zz*@nonospam.com> wrote:
Would someone know why SortedList doesn't work for these two keys?

[ArgumentException: Item has already been added. Key in dictionary:
"xyzbf8d7a21-d4c2-46a7-b005-a15d6ea3a20f" Key being added:
"xyz9097aa36-a64b-406b-8b27-33b42f4890b6"]
System.Collections.SortedList.Add(Object key, Object value) +221

My code looks something like below, the Guid.NewGuid().ToString() is
appended to make sure the key is unique in case of duplicated data.

foreach( CRecord rec in m_sortedList.Values )
{
tmplist.Add( rec.DataRow[fieldName].ToString() +
Guid.NewGuid().ToString(), rec );
}


Looks odd to me. Could you write a short but complete program which
demonstrates the problem? Are you using a specific IComparer which
might be comparing those keys and saying they're equal?

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too

Nov 15 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: Dennis C. Drumm | last post by:
I have a class derived from a SortedList called SystemList that contains a list of objects indexed with a string value. The definition of the objects contained in the SortedList have a boolean...
2
by: arby | last post by:
Hi There. I have a SortedList collection that I add objects of a custom class to. Rather then explain my app, my question is pretty general so.... Using a simple clsDog: ...
3
by: Michael C | last post by:
Hi all, I'm using a SortedList to store data, and want the keys to be compared in case insensitive order, so that mySList is the same as mySList
2
by: Pekka | last post by:
Could somebody say why the piece of code below does not work? My purpose is to renumber keys in a SortedList (after removal of an item) so that the keys would always contain an unbroken sequence of...
2
by: Sean | last post by:
How does one bind a SortedList to anything. If it cant be done why would anyone ever even use a sortedlist? We are currently (via business objects that use interfaces etc) binding gridviews to...
2
by: Prez | last post by:
I started writing .net code yesterday and I am grasping it well enough. I have a few questions about SortedLists. I am using managed C++ if that makes any difference. Of the examples I...
4
by: SHEBERT | last post by:
Here is an example of a SortedList that works as a datasource to the ComboBox and a generic SortedList<that does not works as a datasource to the ComboBox. Why? If I use List and generic List<>,...
4
by: aeshiels | last post by:
Hello, I have a SortedList defined as... SortedList<CUser, CUseruserList = new SortedList<CUser, CUser>(); ....and which to copy it to another sorted list SortedList<CUser,...
6
by: Antonio Paglia | last post by:
Hello. I have tried to insert this items into a SortedList. dic = New SortedList dic.Add("<<", "<<") dic.Add("==", "==") dic.Add(">>", ">>") dic.Add("@@", "@@") dic.Add("??", "??") ...
3
dcharnigo
by: dcharnigo | last post by:
I thought I would be tricky and force the SortedList to not sort using a custom IComparer, I used the following code, but when the list is sorting using the custom sort the accessors become unusable...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.