![]() ![]() Use if you need to access the information in reverse order. Use Queue if you need to access the information in the same order that it is stored in the collection. Stacks and queues are useful when you need temporary storage for information that is, when you might want to discard an element after retrieving its value. 'Contents of the second copy, with duplicates and nulls: ' This code example produces the following output: A stack can be enumerated without disturbing its contents.Ĭonsole.WriteLine("\nPopping '", _ The Contains method is used to show that the string "four" is in the first copy of the stack, after which the Clear method clears the copy and the Count property shows that the stack is empty. The Stack constructor is used again to create a copy of the stack with the order of elements reversed thus, the three null elements are at the end. The elements of the copy are displayed.Īn array twice the size of the stack is created, and the CopyTo method is used to copy the array elements beginning at the middle of the array. The ToArray method is used to create an array and copy the stack elements to it, then the array is passed to the Stack constructor that takes IEnumerable, creating a copy of the stack with the order of the elements reversed. The Peek method is used to look at the next item on the stack, and then the Pop method is used to pop it off. The Pop method is used to pop the first string off the stack. The elements of the stack are enumerated, which does not change the state of the stack. The code example creates a stack of strings with default capacity and uses the Push method to push five strings onto the stack. The following code example demonstrates several methods of the Stack generic class. IEnumerable IReadOnl圜ollection ICollection IEnumerable Examples Implements ICollection, IEnumerable(Of T) Type Parameters Implements ICollection, IEnumerable(Of T), IReadOnl圜ollection(Of T) Public Class Stack(Of T) Interface IEnumerable Public Class Stack(Of T) Interface IReadOnl圜ollection type Stack = class Public class Stack :, 圜ollection, public class Stack :, type Stack = class Public ref class Stack : System::Collections::Generic::IEnumerable, System::Collections::ICollection public class Stack :, 圜ollection, ![]() Public ref class Stack : System::Collections::Generic::IEnumerable, System::Collections::Generic::IReadOnl圜ollection, System::Collections::ICollection generic Represents a variable size last-in-first-out (LIFO) collection of instances of the same specified type.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |