×

VB.Net基本教程

VB.Net 环境设置VB.Net 程序结构VB.Net 基本语法VB.Net 数据类型VB.Net 变量VB.Net 常数和枚举VB.Net 修饰符VB.Net 声明VB.Net 指令VB.Net 运算符VB.Net 决策VB.Net 循环VB.Net 字符串VB.Net 日期和时间VB.Net 数组VB.Net 集合VB.Net 函数VB.Net Sub过程(子程序)VB.Net 类与对象VB.Net 异常处理VB.Net 文件处理VB.Net 基本控制VB.Net 对话框VB.Net 高级表单VB.Net 事件处理

VB.Net 高级教程

VB.Net 正则表达式VB.Net 数据库访问VB.Net Excel工作表VB.Net 发送邮件VB.Net XML处理VB.Net Web编程

VB.Net 有用的资源

VB.Net 有用资源

VB.Net Stack堆栈


VB.Net  集合VB.Net 集合


Stack表示对象的最后进先出集合。 当您需要项目的最后进入,首先访问时使用。 当您在列表中添加项目时,称为推送项目,当您删除它时,它被称为弹出项目。

堆栈类的属性和方法

下表列出了Stack类的一些常用属性:
属性 描述
Count Gets the number of elements contained in the Stack.
获取堆栈中包含的元素数。

下表列出了Stack类的一些常用方法:
S.N 方法名称和用途
1

Public Overridable Sub Clear

Removes all elements from the Stack.

从堆栈中删除所有元素。

2

Public Overridable Function Contains (obj As Object) As Boolean

Determines whether an element is in the Stack.

确定元素是否在堆栈中。

3

Public Overridable Function Peek As Object

Returns the object at the top of the Stack without removing it.

返回堆栈顶部的对象,而不删除它。

4

Public Overridable Function Pop As Object

Removes and returns the object at the top of the Stack.

删除并返回堆栈顶部的对象。

5

Public Overridable Sub Push (obj As Object)

Inserts an object at the top of the Stack.

在堆栈顶部插入一个对象。

6

Public Overridable Function ToArray As Object()

Copies the Stack to a new array.

将堆栈复制到新数组。


示例:

以下示例演示使用堆栈:
Module collections
   Sub Main()
      Dim st As Stack = New Stack()
      st.Push("A")
      st.Push("M")
      st.Push("G")
      st.Push("W")
      Console.WriteLine("Current vbnet-stack: ")
      Dim c As Char
      For Each c In st
          Console.Write(c + " ")
      Next c
      Console.WriteLine()
      st.Push("V")
      st.Push("H")
      Console.WriteLine("The next poppable value in vbnet-stack: {0}", st.Peek())
      Console.WriteLine("Current vbnet-stack: ")
      For Each c In st
          Console.Write(c + " ")
      Next c
      Console.WriteLine()
      Console.WriteLine("Removing values ")
      st.Pop()
      st.Pop()
      st.Pop()
      Console.WriteLine("Current vbnet-stack: ")
      For Each c In st
          Console.Write(c + " ")
      Next c
      Console.ReadKey()
   End Sub
End Module

当上述代码被编译和执行时,它产生以下结果:
Current vbnet-stack: 
W G M A
The next poppable value in vbnet-stack: H
Current vbnet-stack: 
H V W G M A
Removing values
Current vbnet-stack: 
G M A


VB.Net  集合VB.Net 集合


分类导航

关注微信下载离线手册

bootwiki移动版 bootwiki
(群号:472910771)