Mega Code Archive

 
Categories / C# by API / System Collections
 

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();        }     }