×

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 SortedList


VB.Net  集合VB.Net 集合


SortedList类表示按键排序并可通过键和索引访问的键 - 值对的集合。

排序列表是数组和散列表的组合。 它包含可以使用键或索引访问的项目列表。 如果您使用索引访问项目,它是一个ArrayList,如果您使用键访问项目,它是一个Hashtable。 项目的集合始终按键值排序。

SortedList类的属性和方法

下表列出了SortedList类的一些常用属性:
属性 描述
Capacity Gets or sets the capacity of the SortedList.
获取或设置SortedList的容量。
Count Gets the number of elements contained in the SortedList.
获取SortedList中包含的元素数。
IsFixedSize Gets a value indicating whether the SortedList has a fixed size.
获取指示SortedList是否具有固定大小的值。
IsReadOnly Gets a value indicating whether the SortedList is read-only.
获取指示SortedList是否为只读的值。
Item Gets and sets the value associated with a specific key in the SortedList.
获取并设置与SortedList中的特定键相关联的值。
Keys Gets the keys in the SortedList.
获取SortedList中的键。
Values Gets the values in the SortedList.
获取SortedList中的值。

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

Public Overridable Sub Add (key As Object, value As Object)

Adds an element with the specified key and value into the SortedList.

带有指定元素添加可排序列表

2

Public Overridable Sub Clear

Removes all elements from the SortedList.、

从SortedList中删除所有元素。

3

Public Overridable Function ContainsKey (key As Object) As Boolean

Determines whether the SortedList contains a specific key.

确定SortedList是否包含特定键。

4

Public Overridable Function ContainsValue (value As Object) As Boolean

Determines whether the SortedList contains a specific value.

确定SortedList是否包含特定值。

5

Public Overridable Function GetByIndex (index As Integer) As Object

Gets the value at the specified index of the SortedList.

获取SortedList的指定索引处的值。

6

Public Overridable Function GetKey (index As Integer) As Object

Gets the key at the specified index of the SortedList.

获取SortedList的指定索引处的键。

7

Public Overridable Function GetKeyList As IList

Gets the keys in the SortedList.

获取SortedList中的键。

8

Public Overridable Function GetValueList As IList

Gets the values in the SortedList.

获取SortedList中的值。

9

Public Overridable Function IndexOfKey (key As Object) As Integer

Returns the zero-based index of the specified key in the SortedList.

返回SortedList中指定键的从零开始的索引。

10

Public Overridable Function IndexOfValue (value As Object ) As Integer

Returns the zero-based index of the first occurrence of the specified value in the SortedList.

返回SortedList中指定值的第一次出现的从零开始的索引。

11

Public Overridable Sub Remove (key As Object)

Removes the element with the specified key from the SortedList.

从SortedList中删除具有指定键的元素。

12

Public Overridable Sub RemoveAt (index As Integer)

Removes the element at the specified index of SortedList.

删除SortedList的指定索引处的元素。

13

Public Overridable Sub TrimToSize

Sets the capacity to the actual number of elements in the SortedList.

将容量设置为SortedList中的实际元素数。


示例:

下面的例子演示了这个概念:
Module collections
   Sub Main()
      Dim sl As SortedList = New SortedList()
      sl.Add("001", "Zara Ali")
      sl.Add("002", "Abida Rehman")
      sl.Add("003", "Joe Holzner")
      sl.Add("004", "Mausam Benazir Nur")
      sl.Add("005", "M. Amlan")
      sl.Add("006", "M. Arif")
      sl.Add("007", "Ritesh Saikia")
      If (sl.ContainsValue("Nuha Ali")) Then
          Console.WriteLine("This student name is already in the list")
      Else
          sl.Add("008", "Nuha Ali")
      End If
       ' Get a collection of the keys. 
      Dim key As ICollection = sl.Keys
      Dim k As String
      For Each k In key
          Console.WriteLine(" {0} : {1}", k, sl(k))
      Next k
      Console.ReadKey()
   End Sub
End Module

当上述代码被编译和执行时,它产生以下结果:
001: Zara Ali
002: Abida Rehman
003: Joe Holzner
004: Mausam Banazir Nur
005: M. Amlan 
006: M. Arif
007: Ritesh Saikia
008: Nuha Ali


VB.Net  集合VB.Net 集合


分类导航

关注微信下载离线手册

bootwiki移动版 bootwiki
(群号:472910771)