title: How to convert a linkedlist to an array in c#?
body: <p>For a school project I am making an RPN calculator. This calculator has an abstract class Stack where three different implementations of stacks derive from. One of them is a linked list stack. For these stacks I have to show what values are on the stack. To do this I use an array. For my arraystack and list stack it was easy, but I can't figure out how to convert a linked list to an array. What is the best way to do that?</p>
  
  <p>This is the code that I use for my linked list.</p>
  
  <pre><code>public class Node
  {
      public int data;
      public Node next;
  
      public Node(int i)
      {
          data = i;
          next = null;
      }
  
      public void Add(int i)
      {
          if (next == null)
          {
              next = new Node(i);
          }
          else
          {
              next.Add(i);
          }
      }        
  }
  public class MyLinkedList
  {
      private Node headNode;
  
      private int count;
  
      public MyLinkedList()
      {
          headNode = null;
          count = 0;
      }
  
      public int Count()
      {
          return count;
      }
  
      public void Add(int i)
      {
          if (headNode == null)
          {
              headNode = new Node(i);
          }
          else
          {
              headNode.Add(i);
          }
          count++;
      }
  </code></pre>