Stack Constructor ICollection
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 24 25 26 27 |
class Program { static void Main(string[] args) { List<string> redColors = new List<string>() { "Red", "IndianRed", "DarkRed" }; Stack colors = new Stack(redColors); Console.WriteLine("Stack Elements... "); foreach (string color in colors) { Console.WriteLine(color); } colors.Push("Yellow"); Console.WriteLine(); Console.WriteLine("After Push 'Yellow', Now Stack Elements... "); foreach (string color in colors) { Console.WriteLine(color); } Console.ReadLine(); } } |
Output:
1 2 3 4 5 6 7 8 9 10 11 12 |
Stack Elements... DarkRed IndianRed Red After Push 'Yellow', Now Stack Elements... Yellow DarkRed IndianRed Red |