public void Disbind(Node node1, Node node2) { if (node2.Edges.Count < node1.Edges.Count) { Node temp = node1; node1 = node2; node2 = temp; } List <Edge> toRemove = new List <Edge>(); foreach (var edge in node1.Edges) { if (edge.Node1.Equals(node2) || edge.Node2.Equals(node2)) { toRemove.Add(edge); Edges.Remove(edge); node2.RemoveEdge(edge); } } foreach (var edge in toRemove) { node1.RemoveEdge(edge); } }