IndexOf 方法

傳回 ArrayList 物件中第一次出現之值的零基索引。

語法

Object.IndexOf(Element,StartIndex)

引數:

  • Object必要。一律是 ArrayList 物件的名稱。

  • Element必要。要在 ArrayList 物件中尋找的物件。

  • StartIndex必要。搜尋的零基開始索引

傳回

如果找到的話,會傳回 ArrayList 中,從 StartIndex 到最後一個元素的範圍內,第一次出現之值的零基索引;否則會傳回 -1

備註

下列範例說明 IndexOf 方法的用法。

範例 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)

'Get the Index of the Element
Index = Obj.IndexOf(40, 0)
'Output: 1
Index = Obj.IndexOf(50, 0)
'Output: -1