Assembly : mscorlib (dans mscorlib.dll)
SyntaxePublic Overridable Function Pop As Object
Dim instance As Stack Dim returnValue As Object returnValue = instance.Pop
public virtual Object Pop ()
public:
virtual Object^ Pop ()
public Object Pop ()
public function Pop () : Object
Valeur de retour
Object supprimé du haut de Stack.
NotesCette méthode est analogue à la méthode Peek, mais Peek ne modifie pas le Stack.
référence Null (Nothing en Visual Basic) peut faire l'objet d'un push sur Stack en tant qu'espace réservé, si nécessaire. Pour différencier une valeur null de la fin de la pile, vérifiez la propriété Count ou interceptez InvalidOperationException, qui est levée si Stack est vide.
Stack est implémenté sous forme de mémoire tampon circulaire. Cette méthode est une opération O(1).
ExempleL'exemple suivant décrit l'ajout d'éléments à Stack, la suppression d'éléments de Stack ou l'affichage de l'élément situé en haut de Stack.
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("The") myStack.Push("quick") myStack.Push("brown") myStack.Push("fox") ' Displays the Stack. Console.Write("Stack values:") PrintValues(myStack, ControlChars.Tab) ' Removes an element from the Stack. Console.WriteLine("(Pop)" & ControlChars.Tab & ControlChars.Tab & _ "{0}", myStack.Pop()) ' Displays the Stack. Console.Write("Stack values:") PrintValues(myStack, ControlChars.Tab) ' Removes another element from the Stack. Console.WriteLine("(Pop)" & ControlChars.Tab & ControlChars.Tab & _ "{0}", myStack.Pop()) ' Displays the Stack. Console.Write("Stack values:") PrintValues(myStack, ControlChars.Tab) ' Views the first element in the Stack but does not remove it. Console.WriteLine("(Peek)" & ControlChars.Tab & ControlChars.Tab & _ "{0}", myStack.Peek()) ' Displays the Stack. Console.Write("Stack values:") PrintValues(myStack, ControlChars.Tab) End Sub Public Shared Sub PrintValues(myCollection As IEnumerable, mySeparator As Char) Dim obj As [Object] For Each obj In myCollection Console.Write("{0}{1}", mySeparator, obj) Next obj Console.WriteLine() End Sub 'PrintValues End Class 'SamplesStack ' This code produces the following output. ' ' Stack values: fox brown quick The ' (Pop) fox ' Stack values: brown quick The ' (Pop) brown ' Stack values: quick The ' (Peek) quick ' Stack values: quick The
using System; using System.Collections; public class SamplesStack { public static void Main() { // Creates and initializes a new Stack. Stack myStack = new Stack(); myStack.Push( "The" ); myStack.Push( "quick" ); myStack.Push( "brown" ); myStack.Push( "fox" ); // Displays the Stack. Console.Write( "Stack values:" ); PrintValues( myStack, '\t' ); // Removes an element from the Stack. Console.WriteLine( "(Pop)\t\t{0}", myStack.Pop() ); // Displays the Stack. Console.Write( "Stack values:" ); PrintValues( myStack, '\t' ); // Removes another element from the Stack. Console.WriteLine( "(Pop)\t\t{0}", myStack.Pop() ); // Displays the Stack. Console.Write( "Stack values:" ); PrintValues( myStack, '\t' ); // Views the first element in the Stack but does not remove it. Console.WriteLine( "(Peek)\t\t{0}", myStack.Peek() ); // Displays the Stack. Console.Write( "Stack values:" ); PrintValues( myStack, '\t' ); } public static void PrintValues( IEnumerable myCollection, char mySeparator ) { foreach ( Object obj in myCollection ) Console.Write( "{0}{1}", mySeparator, obj ); Console.WriteLine(); } } /* This code produces the following output. Stack values: fox brown quick The (Pop) fox Stack values: brown quick The (Pop) brown Stack values: quick The (Peek) quick Stack values: quick The */
using namespace System; using namespace System::Collections; void PrintValues( IEnumerable^ myCollection, char mySeparator ); int main() { // Creates and initializes a new Stack. Stack^ myStack = gcnew Stack; myStack->Push( "The" ); myStack->Push( "quick" ); myStack->Push( "brown" ); myStack->Push( "fox" ); // Displays the Stack. Console::Write( "Stack values:" ); PrintValues( myStack, '\t' ); // Removes an element from the Stack. Console::WriteLine( "(Pop)\t\t{0}", myStack->Pop() ); // Displays the Stack. Console::Write( "Stack values:" ); PrintValues( myStack, '\t' ); // Removes another element from the Stack. Console::WriteLine( "(Pop)\t\t{0}", myStack->Pop() ); // Displays the Stack. Console::Write( "Stack values:" ); PrintValues( myStack, '\t' ); // Views the first element in the Stack but does not remove it. Console::WriteLine( "(Peek)\t\t{0}", myStack->Peek() ); // Displays the Stack. Console::Write( "Stack values:" ); PrintValues( myStack, '\t' ); } void PrintValues( IEnumerable^ myCollection, char mySeparator ) { IEnumerator^ myEnum = myCollection->GetEnumerator(); while ( myEnum->MoveNext() ) { Object^ obj = safe_cast<Object^>(myEnum->Current); Console::Write( "{0}{1}", mySeparator, obj ); } Console::WriteLine(); } /* This code produces the following output. Stack values: fox brown quick The (Pop) fox Stack values: brown quick The (Pop) brown Stack values: quick The (Peek) quick Stack values: quick The */
import System.*; import System.Collections.*; public class SamplesStack { public static void main(String[] args) { // Creates and initializes a new Stack. Stack myStack = new Stack(); myStack.Push("The"); myStack.Push("quick"); myStack.Push("brown"); myStack.Push("fox"); // Displays the Stack. Console.Write("Stack values:"); PrintValues(myStack, '\t'); // Removes an element from the Stack. Console.WriteLine("(Pop)\t\t{0}", myStack.Pop()); // Displays the Stack. Console.Write("Stack values:"); PrintValues(myStack, '\t'); // Removes another element from the Stack. Console.WriteLine("(Pop)\t\t{0}", myStack.Pop()); // Displays the Stack. Console.Write("Stack values:"); PrintValues(myStack, '\t'); // Views the first element in the Stack but does not remove it. Console.WriteLine("(Peek)\t\t{0}", myStack.Peek()); // Displays the Stack. Console.Write("Stack values:"); PrintValues(myStack, '\t'); } //main public static void PrintValues(IEnumerable myCollection, char mySeparator) { IEnumerator l_objmyEnum = myCollection.GetEnumerator(); while (l_objmyEnum.MoveNext()) { Console.Write("{0}{1}", System.Convert.ToString(mySeparator), System.Convert.ToString(l_objmyEnum.get_Current())); } Console.WriteLine(); } //PrintValues } //SamplesStack /* This code produces the following output. Stack values: fox brown quick The (Pop) fox Stack values: brown quick The (Pop) brown Stack values: quick The (Peek) quick Stack values: quick The */
Plates-formesWindows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile pour Pocket PC, Windows Mobile pour Smartphone, Windows Server 2003, Windows XP Édition Media Center, Windows XP Professionnel Édition x64, Windows XP SP2, Windows XP Starter Edition
Le .NET Framework ne prend pas en charge toutes les versions de chaque plate-forme. Pour obtenir la liste des versions prises en charge, consultez Configuration requise.
Informations de version
Outils (masquer)
S'enregistrer
Liste des Membres
Qui est en ligne?
FAQ