I have a problem very much like the one mentioned here:
ArgumentOutOfRangeException Was Unhandled
I believe that contiguousLines[columnNum].Add(...)
is what is causing the error because I am indexing with columnNum
List<line> freeLines = new List<line>();
List<List<line>> contiguousLines = new List<List<line>>();
while(freeLines.Count > 0)
{
int columnNum = contiguousLines.Count;
contiguousLines[columnNum].Add(freeLines[0]);
freeLines.RemoveAt(0);
for(int i = 0; i < freeLines.Count; i++)
{
int last = contiguousLines[columnNum].Count;
if(contiguousLines[columnNum][last].upDown(freeLines[i]))
{
contiguousLines[columnNum].Add(freeLines[i]);
freeLines.RemoveAt(i);
i = -1;
}
}
// Further code that pulls individual elements from freeLines and
// is intended to place them into contiguousLines.
}
The function upDown
just compares Start and End points of the lines to see if one (freeLines[i]
) is the downstream of the other (contiguousLines[columnNum]
).
System.ArgumentOutOfRangeException was unhandled Message=Index was out of range. Must be non-negative and less than the size of the collection. Parameter name: index
What is the proper syntax when dealing with a List of Lists?
(Note: I don't often program in C# and this project is something I wrote and have working in C++ only to be later informed C# would play better with the rest of the utilities for my job. In C++ I used vectors for my containers, but apparently copy/pasting the logic won't work as there is some nuance of Lists that I am unaware of.)
I suppose it is also possible to just make a ContiguousLine class that holds a list of Lines, then add to a List<ContiguousLine>
from freeLines
. Even if that were to be a better solution, I am still curious why I can not address a List of Lists of Lines in this way.