C# Stack Stack(Int32)
Description
Initializes a new
instance of the Stack
Syntax
public Stack(
int capacity
)
Parameters
capacity
- The initial number of elements that the Stackcan 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.