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は、Keyと完全に一致するキーを持つ要素がコレクションに含まれている場合、Trueを返します。 それ以外の場合、 Contains は Falseを返します。 キー値と一致する場合、大文字と小文字は無視されます。
Visual Basic Collectionは、キーを持つ要素と、キーのない他の要素を保持できます。 これは、 Add メソッドの呼び出しが省略可能な Key パラメーターに引数を提供するかどうかによって異なります。