title: Making the double linked List generic
body: <p>I am working on a C# console application. I am trying to make the double linked list Generic. </p>
  
  <p>I have this class:</p>
  
  <pre><code>public class Node&lt;T&gt;
  {
      public T data;
      public Node&lt;T&gt; next;
      public Node&lt;T&gt; previous;
  
      public Node(T d) =&gt; (data, next, previous) = (d, null, null);
      public void DisplayNode() =&gt; Console.Write("{" + data + "}");
  }
  </code></pre>
  
  <p>and the actual double linked class:</p>
  
  <pre><code>public class DoubleLinkedList&lt;T&gt;
  {
      private Node&lt;T&gt; _first;
      private Node&lt;T&gt; _last;
      // internal Node head;
  
      public DoubleLinkedList(Node&lt;T&gt; first, Node&lt;T&gt; last) =&gt; (_first, _last) = (first, last);
      public DoubleLinkedList() { }
  
      public bool InsertAfter(int key, T data)
      {
          Node&lt;T&gt; current = _first;
  
          while (current.data != key)
          {
              current = current.next;
              if (current == null)
                  return false;
          }
  
          Node&lt;T&gt; newNode = new Node&lt;T&gt;(data);
          newNode.data = data;
  
          if (current == _last) (current.next, _last) = (null, newNode);
          else 
          {
              newNode.next = current.next;
              current.next.previous = newNode;
          }
  
          newNode.previous = current;
          current.next = newNode;
  
          return true;
      }
  </code></pre>
  
  <p>But I get an error on this line:</p>
  
  <pre><code>while (current.data != key)
  </code></pre>
  
  <p>saying:</p>
  
  <blockquote>
    <p>CS0019  C# Operator '!=' cannot be applied to operands of type 'T' and
    'T'</p>
  </blockquote>
  
  <p>So my question is: How to solve this error?</p>
  
  <p>Thank you</p>