473,322 Members | 1,526 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,322 software developers and data experts.

SortedList Issue

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
2 1476
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
Thanks for the quick reply but I figured it out :)

Cheers
//KrippZ

Mar 31 '06 #3

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

Similar topics

1
by: gerrod | last post by:
Hi - Does anyone know a way to created a SortedList (in the System.Collections namespace) that will sort on VALUES instead of KEYS... ? The scenario is this - I have a SortedList containing...
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: ...
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: 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: sck10 | last post by:
Hello, I have a method in my codefile that builds a sorted list (see CodeFile). I am trying to create a class that does the same thing (see App_Code). CodeFile...
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,...
1
by: raylopez99 | last post by:
I seem to get name collision between the Generic collection SortedList and C++.NET Framework collection SortedList. How to resolve? Here are the libraries that seem to clash:...
6
by: n3tx | last post by:
Hi! I have a problem with sortedlist, i guess i dont understand how it works. I have a method called GetPublishingPlaces that returns an IList<PublishingPlace> (ex. contains 11 rows) I want...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
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...

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.