C# Stack Push

Description

Stack Push inserts an object at the top of the Stack.

Syntax

Stack.Push has the following syntax.


public virtual void Push(
  Object obj
)

Parameters

Stack.Push has the following parameters.

  • obj - The Object to push onto the Stack. The value can be null.

Returns

Stack.Push method returns

Example

The following example shows how to add elements to the Stack.


/*from  w w w.j a va 2  s  .  c o  m*/
using System;
using System.Collections;
public class SamplesStack
{
    public static void Main()
    {
        Stack myStack = new Stack();
        myStack.Push("A");
        myStack.Push("B");
        myStack.Push("java2s.com");

        foreach (Object obj in myStack)
        {
            Console.Write(obj);
        }
    }

}

The code above generates the following result.





















Home »
  C# Tutorial »
    System.Collections »




ArrayList
BitArray
Comparer
Hashtable
Queue
SortedList
Stack