C# Stack Push
Description
Inserts an object at the top of the Stack.
Syntax
Stack.Push
has the following syntax.
public void Push(
T item
)
Parameters
Stack.Push
has the following parameters.
item
- The object to push onto the Stack. The value can be null for reference types.
Example
using System;/*from w w w .j a va 2 s . c o m*/
using System.Collections.Generic;
class Example
{
public static void Main()
{
Stack<string> numbers = new Stack<string>();
numbers.Push("one");
numbers.Push("two");
numbers.Push("three");
numbers.Push("four");
numbers.Push("five");
foreach( string number in numbers )
{
Console.WriteLine(number);
}
}
}
The code above generates the following result.