title: Shuffling a Stack<T>
body: <pre><code>    public static void Shuffle&lt;T&gt; ( this Stack&lt;T&gt; stack )
      {
          List&lt;T&gt; list = stack.ToList ();
          list.Shuffle ();
          stack = list.ToStack ();
      }
  
      public static void Shuffle&lt;T&gt; ( this List&lt;T&gt; list )
      {
          for ( int i = 0; i &lt; list.Count; i++ )
          {
              int num = Form1.rnd.Next ( list.Count );
              T temp = list[i];
              list[i] = list[num];
              list[num] = temp;
          }
      }
  
      public static Stack&lt;T&gt; ToStack&lt;T&gt; ( this List&lt;T&gt; list )
      {
          Stack&lt;T&gt; stack = new Stack&lt;T&gt; ();
          foreach ( T t in list )
              stack.Push ( t );
  
          return stack;
      }
  </code></pre>
  
  <p>Above is my attempt to shuffle a generic stack. However, although the List Shuffle extension method works, the Stack Shuffle does not work as intended. It is as if the Shuffle call in the middle isn't called at all. Instead, it remains the same list, un-shuffled. So I presume the problem is in the ToStack function. Can someone please explain my error? Thanks in advance!</p>