title: How do I extract a LinkedListNode<T> from a LinkedList<T>
body: <p>I have a LinkedList that I am using to track consecutive numbers that are sent to this class. (I ultimately want to find the missing numbers).</p>
  
  <p>I now need to use the method <a href="http://msdn.microsoft.com/en-us/library/0hxfc7s5%28v=vs.80%29" rel="noreferrer">ranges.AddAfter(recentNode,someNewNode)</a>, but I can't do it by casting.  What am I missing?</p>
  
  <pre><code>class ContiguousData 
  {
      LinkedList&lt;ContiguousDataValue&gt; ranges = new LinkedList&lt;ContiguousDataValue&gt;();
  
      public void AddValue(int val)
      {
          LinkedListNode&lt;ContiguousDataValue&gt; recentNode = null;
  
          foreach (var range in ranges)
          {
              if (val &gt; range.UpperInt)
              {
                  if (val == range.UpperInt + 1)
                      range.UpperInt = val;
                  else
                  {
                      if (recentNode == null)
                          ranges.AddFirst(new ContiguousDataValue() { UpperInt = val, LowerInt = val });
                      else
                          ranges.AddAfter(recentNode, new ContiguousDataValue() { UpperInt = val, LowerInt = val });
                  }
                  break;
              }
              else if (val &lt; range.LowerInt)
              {
                  if (val == range.LowerInt - 1)
                      range.LowerInt = val;
                  else
                  {
                      // do  more logic (incomplete)
                  }
              }
  
             // Compiler error
              recentNode = (LinkedListNode&lt;ContiguousDataValue&gt;)range;
          }
  
          if (ranges.Count == 0)
          {
              ranges.AddFirst(new ContiguousDataValue() { UpperInt = val, LowerInt = val });
              return;
          }
      }
  
      internal class ContiguousDataValue
      {
          public int UpperInt { get; set; }
          public int LowerInt { get; set; }
      }
  }
  </code></pre>
  
  <p>Since casting doesn't work, how do I convert <code>range</code> to a <code>LinkedListNode&lt;T&gt;</code>?</p>