C# Stack Stack(Int32)

Description

Initializes a new instance of the Stack class that is empty and has the specified initial capacity or the default initial capacity, whichever is greater.

Syntax


public Stack(
  int capacity
)

Parameters

  • capacity - The initial number of elements that the Stack can contain.

Example


using System;/*from w ww  .jav a 2 s . c  o  m*/
using System.Collections.Generic;

class Example
{
    public static void Main()
    {
        Stack<string> numbers = new Stack<string>(10);
        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.





















Home »
  C# Tutorial »
    System.Collections.Generic »




HashSet
LinkedList
LinkedListNode
List
Queue
SortedSet
Stack