public void SetVisitItemSafely(int index, VisitItem item) { if (index >= Visited.Length) { InitializeVisited(index + 1); } Visited[index] = item; }
private void InitializeVisited(int count) { var template = new VisitItem(-1, -1); var index = 0; if (Visited != null) // Make sure to copy the old data to the new array { var tempArray = new VisitItem[count]; Visited.CopyTo(tempArray, 0); index = Visited.Length; Visited = tempArray; } else { Visited = new VisitItem[count]; } for (int i = index; i < count; i++) { Visited[i] = template; } }