确定某个元素是否位于 ArrayList 对象中。
语法
Object.Contains(Element)
参数:
Object:必需。始终为 ArrayList 对象的名称。
Element:必需。要在 ArrayList 对象中查找的元素。
返回
如果在 ArrayList 对象中找到元素,则为 True;否则为 False
注释
以下示例说明了 Contains 方法的用法。
示例 1:
'Create ArrayList Object
Dim Obj
Set Obj = CreateObject("System.Collections.ArrayList")
'Add Elements to the end of the ArrayList Object
Dim Index
Index = Obj.Add(10)
Index = Obj.Add(40)
Index = Obj.Add(20)
'Determines whether an element is in the ArrayList object
If Obj.Contains(40) Then 'Returns True
'Operations based on the requirement when ArrayList contains 40
Else
'Operations based on the requirement when ArrayList doesn’t contains 40
End If
'Output: True (Obj contains 40)