Collection.Contains(String) 方法
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
傳回值,指出 Visual Basic Collection 物件是否包含具有特定機碼的項目。
public:
bool Contains(System::String ^ Key);
public bool Contains (string Key);
member this.Contains : string -> bool
Public Function Contains (Key As String) As Boolean
參數
- Key
- String
必要。
String 運算式,其指定要搜尋集合項目的索引鍵。
傳回
如果 Visual Basic Collection 物件包含具有特定機碼的元素,則為 true;否則為 false。
範例
Dim customers As New Microsoft.VisualBasic.Collection()
Dim accountNumber As String = "1234"
' Insert code that obtains new customer objects.
' Use the new customer's account number as the key.
customers.Add(newCustomer, accountNumber)
' The preceding statements can be repeated for several customers.
Dim searchNumber As String = "1234"
' Insert code to obtain an account number to search for.
If customers.Contains(searchNumber) Then
MsgBox("The desired customer is in the collection.")
Else
MsgBox("The desired customer is not in the collection.")
End If
如果您想要使用其索引鍵搜尋集合中的專案,請記得在每次呼叫 Add 方法時提供 Key 自變數。
備註
Contains
True如果集合包含索引鍵完全相符Key的專案,則會傳回 。 否則,Contains 會傳回 False。 比對索引鍵值時,會忽略大小寫。
Visual Basic Collection 可以保存一些具有索引鍵的元素,以及其他沒有索引鍵的專案。 這取決於方法的呼叫 Add 是否提供選擇性 Key 參數的自變數。