SortedList 类的属性和方法
下表列出了SortedList类的一些常用属性-
属性 |
描述 |
Capacity |
获取或设置SortedList的容量。 |
Count |
获取SortedList中包含的元素数。 |
IsFixedSize |
获取一个值,该值指示SortedList是否具有固定大小。 |
IsReadOnly |
获取一个值,该值指示SortedList是否为只读。 |
Item |
获取并设置与SortedList中的特定键关联的值。 |
Keys |
获取SortedList中的键。 |
Values |
获取SortedList中的值 |
下表列出了SortedList类的一些常用方法--
方法 |
描述 |
Public Overridable Sub Add (key As Object, value As Object) |
将具有指定键和值的元素添加到SortedList中。 |
Public Overridable Sub Clear |
从SortedList中删除所有元素。 |
Public Overridable Function ContainsKey (key As Object) As Boolean |
确定SortedList是否包含特定键。 |
Public Overridable Function ContainsValue (value As Object) As Boolean |
确定SortedList是否包含特定值。 |
Public Overridable Function GetByIndex (index As Integer) As Object |
获取SortedList指定索引处的值。 |
Public Overridable Function GetKey (index As Integer) As Object |
获取SortedList指定索引处的键。 |
Public Overridable Function GetKeyList As IList |
获取SortedList中的键。 |
Public Overridable Function GetValueList As IList |
获取SortedList中的值。 |
Public Overridable Function IndexOfKey (key As Object) As Integer |
返回SortedList中指定键的从零开始的索引。 |
Public Overridable Function IndexOfValue (value As Object ) As Integer |
返回SortedList中第一次出现的指定值的从零开始的索引。 |
Public Overridable Sub Remove (key As Object) |
从SortedList中移除具有指定键的元素。 |
Public Overridable Sub RemoveAt (index As Integer) |
删除SortedList指定索引处的元素。 |
Public Overridable Sub TrimToSize |
将容量设置为SortedList中元素的实际数量。 |
示例:
编译并执行上述代码后,将产生以下结果-