Initialize a Stack with specified initial capacity. How to initialize a new instance of empty Stack class with specified initial capacity
C# Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | class Program { static void Main(string[] args) { Stack colors = new Stack(100); Console.WriteLine("Stack initialized with initial capacity 100"); colors.Push("Ivory"); colors.Push("IndianRed"); colors.Push("DarkGreen"); colors.Push("ForestGreen"); Console.WriteLine("\nStack Elements... "); foreach (string color in colors) { Console.WriteLine(color); } Console.ReadLine(); } } |
Output:
1 2 3 4 5 6 7 8 9 | Stack initialized with initial capacity 100 Stack Elements... ForestGreen DarkGreen IndianRed Ivory |