private static void unToggleEventsThatAreTooClose(DateTime time) { for (int i = 0; i < toggledNodes.Count; i++) { ToggleButton button = toggledNodes[i]; if (button.GetType() == typeof(Node.Node)) { Node.Node node = (Node.Node)button; DateTime nodesTime = node.GetBlockTime(); if (EventIsTooClose(nodesTime, time)) { node.ToggleBlock(); toggledNodes.Remove(node); i--; } } else if (button.GetType() == typeof(StackedNodes)) { StackedNodes node = (StackedNodes)button; DateTime nodesTime = node.GetBlockTime(); if (EventIsTooClose(nodesTime, time)) { node.ToggleBlock(); toggledNodes.Remove(node); i--; } } } }