決定某個元素是否在 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)