Collection.Contains(String) メソッド

定義

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は、Keyと完全に一致するキーを持つ要素がコレクションに含まれている場合、Trueを返します。 それ以外の場合、 ContainsFalseを返します。 キー値と一致する場合、大文字と小文字は無視されます。

Visual Basic Collectionは、キーを持つ要素と、キーのない他の要素を保持できます。 これは、 Add メソッドの呼び出しが省略可能な Key パラメーターに引数を提供するかどうかによって異なります。

適用対象