First, you create a new object of type
System.Collections.Stack called myStack .You
then add items to the stack by using the Push method and passing in the object you
want to add to the top of the stack.You can then retrieve items from the top of the stack .
(remember a stack is last-in-first-out, or LIFO) by using the Pop method.The item is
returned as type of object, so if you need to convert it into a string, as in the following
example, you simply call the ToString() method. Otherwise, you'll need to cast it to
the type of object that you need.
In <script runat="server" /> block or codebehind:
'Make sure System.Collections is imported
Sub Page_Load(sender As Object, e As EventArgs)
Dim myStack As New Stack()
myStack.Push("One")
myStack.Push("Two")
myStack.Push("Three")
While myStack.Count > 0
Response.Write(myStack.Pop().ToString() & "<br>")
End While
End Sub
For more info see:
Stack class-http://msdn.microsoft.com/library/en-us/cpref/html/
frlrfSystemCollectionsStackClassTopic.asp
No comments:
Post a Comment