[Visual Basic]
Imports System
Imports System.Collections
Imports Microsoft.VisualBasic
Public Class SamplesStack
Public Shared Sub Main()
' Creates and initializes a new Stack.
Dim myStack As New Stack()
myStack.Push("Hello")
myStack.Push("World")
myStack.Push("!")
' Displays the properties and values of the Stack.
Console.WriteLine("myStack")
Console.WriteLine(ControlChars.Tab & "Count: {0}", myStack.Count)
Console.Write(ControlChars.Tab & "Values:")
PrintValues(myStack)
End Sub
Public Shared Sub PrintValues(myCollection As IEnumerable)
Dim myEnumerator As System.Collections.IEnumerator = _
myCollection.GetEnumerator()
While myEnumerator.MoveNext()
Console.Write(ControlChars.Tab & "{0}", myEnumerator.Current)
End While
Console.WriteLine()
End Sub
End Class
' This code produces the following output.
'
' myStack
' Count: 3
' Values: ! World Hello
[C#]
using System;
using System.Collections;
public class SamplesStack {
public static void Main() {
// Creates and initializes a new Stack.
Stack myStack = new Stack();
myStack.Push("Hello");
myStack.Push("World");
myStack.Push("!");
// Displays the properties and values of the Stack.
Console.WriteLine( "myStack" );
Console.WriteLine( "\tCount: {0}", myStack.Count );
Console.Write( "\tValues:" );
PrintValues( myStack );
}
public static void PrintValues( IEnumerable myCollection ) {
System.Collections.IEnumerator myEnumerator = myCollection.GetEnumerator();
while ( myEnumerator.MoveNext() )
Console.Write( "\t{0}", myEnumerator.Current );
Console.WriteLine();
}
}
/*
This code produces the following output.