Stack.ToArray() : Stack « System.Collections « C# / C Sharp by API





Stack.ToArray()

  
 using System;
 using System.Collections;

    public class TesterStackArray
    {
       public void Run()
       {
           Stack intStack = new Stack();
           for (int i = 1;i<5;i++){
               intStack.Push(i*5);
           }
           const int arraySize = 10;
           int[] testArray = new int[arraySize];
           for (int i = 1; i < arraySize; i++)
           {
               testArray[i] = i * 100;
           }
           Console.WriteLine("\nContents of the test array");
           DisplayValues( testArray );

           intStack.CopyTo( testArray, 3 );
           Console.WriteLine( "\nTestArray after copy:  ");
           DisplayValues( testArray );
           Object[] myArray = intStack.ToArray();
           Console.WriteLine( "\nThe new  array:" );
           DisplayValues( myArray );

       }
       public static void DisplayValues(IEnumerable myCollection ){
            foreach (object o in myCollection){
                Console.WriteLine(o);
            }
        }

       static void Main()
       {
          TesterStackArray t = new TesterStackArray();
          t.Run();
       }
    }

   
    
  










Related examples in the same category

1.Stack.Count
2.Stack.Peek()