title: Having trouble with removing a node from a Doubly linked List
body: <p>I have a Doubly Linked List and I method which is supposed to remove a given node. It originally worked with my 3 test nodes when I originally developed the code but when I added more Nodes to the Doubly Linked List it stopped working, now I am getting an NullReferenceException:"Object reference not set to an instance of an object" I know I could just use a generic linked list but I am trying to learn how doubly linked lists work.</p>
  
  <p>I will mark the line in my code where I am getting this exception with "**" at the beginning of the line(it is in the RemoveNode method in the Doubly Linked List class).</p>
  
  <p>Here is my code:</p>
  
  <p>Doubly Linked List class:</p>
  
  <pre><code>class DoublyLinkedList
  {
      public Node head, current;
  
      public void AddNode(object n) // add a new node 
      {
          if (head == null)
          {
              head = new Node(n); //head is pointed to the 1st node in list 
              current = head;
          }
          else
          {
              while (current.next != null)
              {
                  current = current.next;
              }
  
              current.next = new Node(n, current); //current is pointed to the newly added node 
          }
      }
  
      public Node FindNode(object n) //Find a given node in the DLL
      {
          current = head;
          while ((current != null) &amp;&amp; (current.data != n))
              current = current.next;
  
          if (current == null)
              return null;
          else
              return current;                    
      }
  
  
      public string RemoveNode(object n)//remove nodes
      {
          String Output = "";
  
          if (head == null)
          {
              Output += "\r\nLink list is empty";
          }
          else
          {
              current = FindNode(n);
  
              if (current == null)
              {
                  Output += "Node not found in Doubly Linked List\r\n";
              }
              else
              {                   
                  ****current.next.prev = current.prev;**         
                  current.prev.next = current.next;
                  current.prev = null;
                  current.next = null;
                  Output += "Node removed from Doubly Linked List\r\n";
              }
          }
          return Output; 
      }
  
      public String PrintNode() // print nodes 
      {
          String Output = "";
  
          Node printNode = head;
          if (printNode != null)
          {
              while (printNode != null)
              {
                  Output += printNode.data.ToString() + "\r\n";
                  printNode = printNode.next;
              }
          }
          else
          {
              Output += "No items in Doubly Linked List";
          }
          return Output;
      }
  
  }
  </code></pre>
  
  <p>Node class:</p>
  
  <pre><code>class Node
  {
      public Node prev, next; // to store the links 
      public object data; // to store the data in a node 
  
      public Node()
      {
          this.prev = null;
          this.next = null;
      }
  
      public Node(object data)
      {
          this.data = data;
          this.prev = null;
          this.next = null;
      }
  
      public Node(object data, Node prev)
      {
          this.data = data;
          this.prev = prev;
          this.next = null;
      }
  
      public Node(object data, Node prev, Node next)
      {
          this.data = data;
          this.prev = prev;
          this.next = next;
      } 
  
  }
  </code></pre>