public static void RemoveFromList(ref DLink pCurrentHead, DLink pNodeToRemove) { Debug.Assert(pNodeToRemove != null); DLink pTmpNode = pNodeToRemove; // If pNode is head of list if (pCurrentHead == pNodeToRemove) { pCurrentHead = pCurrentHead.GetNext(); if (pCurrentHead != null) { // Set prev to null - it's the new list head pCurrentHead.SetPrev(null); } } else { if (pTmpNode.GetPrev() != null) { // Set the previous node's next to pNode's next pTmpNode.GetPrev().SetNext(pNodeToRemove.GetNext()); } if (pTmpNode.GetNext() != null) { // Set the next node's prev to pNodes prev pTmpNode.GetNext().SetPrev(pTmpNode.GetPrev()); } } }