K
KrippZ
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
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