By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,186 Members | 1,480 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,186 IT Pros & Developers. It's quick & easy.

SortedList Issue

P: n/a
Hello I'm having some problems with a a sortedList in C#.
My set is as follows: I have a sortedList as a class variable
(DataList) I inisiate it in my constructor with DataList = new
SortedList().

I add other sorted lists to DataList with the following code:
internal void addData(System.Collections.SortedList inList) {

System.Collections.SortedList inNewList = new SortedList();
try
{
string inListName = (string)inList["owner"];
if(!DataList.ContainsKey(inListName))
{
for(int i=0; i<inList.Count; i++)
{
string key = (string)inList.GetKey(i);
object val = (object)inList.GetByIndex(i);
inNewList.Add(key,val);
}

DataList.Add(inListName, inNewList);

}
else
{
DataList.Remove(inListName);
for(int i=0; i<inList.Count; i++)
{
string key = (string)inList.GetKey(i);
object val = (object)inList.GetByIndex(i);
inNewList.Add(key,val);
}

DataList.Add(inListName, inNewList);
}

}
catch(Exception e)
{
Console.WriteLine("error in DataList");
ErrorLogger.ErrorLogClass.WriteErrorLog(e.ToString ());
}
}

The problem I have is when I have added the 9th sortedlist to DataList,
then the DataList is cleared somehow and ends up with Count = 0;
Thefunny thing is that all works perfect until a add the 9th
sortedlist.

I don't have clue to what's wrong here :)
Cheers
//KrippZ

Mar 30 '06 #1
Share this Question
Share on Google+
2 Replies


P: n/a
KrippZ wrote:
Hello I'm having some problems with a a sortedList in C#.
My set is as follows: I have a sortedList as a class variable
(DataList) I inisiate it in my constructor with DataList = new
SortedList().

I add other sorted lists to DataList with the following code:
internal void addData(System.Collections.SortedList inList)


Could you post a short but complete program that demonstrates the
problem?

See http://www.pobox.com/~skeet/csharp/complete.html for what I mean by
that.

Jon

Mar 30 '06 #2

P: n/a
Thanks for the quick reply but I figured it out :)

Cheers
//KrippZ

Mar 31 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.