Contains 메서드(Collection 개체)

업데이트: 2007년 11월

Visual Basic Collection 개체에 특정 키를 가진 요소가 있는지 여부를 나타내는 Boolean 값을 반환합니다.

Public Function Contains( _
    ByVal Key As String _
) As Boolean

매개 변수

  • Key
    필수적 요소. 컬렉션의 요소를 검색할 키를 지정하는 String 식입니다.

예외/오류 코드

예외 형식

오류 번호

조건

ArgumentException

5

지정한 Key가 Nothing입니다.

비구조적 오류 처리를 사용하는 Visual Basic 6.0 응용 프로그램을 업그레이드하는 경우에는 "오류 번호" 열을 참조하십시오. 오류 번호를 Number 속성(Err 개체)과 비교할 수 있습니다. 그러나 가능하면 이러한 오류 제어 방법을 Visual Basic의 구조적 예외 처리 개요에 설명된 방식으로 바꾸는 것이 좋습니다.

설명

컬렉션에 Key와 정확하게 일치하는 키를 가진 요소가 있으면 Contains는 True를 반환합니다. 그렇지 않으면 Contains는 False를 반환합니다.

Visual Basic Collection에는 키가 있는 요소와 키가 없는 요소가 모두 포함될 수 있습니다. 키가 있고 없음은 Add 메서드(Collection 개체) 호출에서 선택적 요소인 Key 매개 변수에 인수를 지정하는지 여부에 따라 결정됩니다.

예제

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 인수를 지정해야 합니다.

요구 사항

네임스페이스: Microsoft.VisualBasic

**모듈:**Collection

**어셈블리:**Visual Basic 런타임 라이브러리(Microsoft.VisualBasic.dll)

참고 항목

참조

Collection 개체(Visual Basic)

Item 속성(Collection 개체)

Count 속성(Collection 개체)

Add 메서드(Collection 개체)

Remove 메서드(Collection 개체)

Clear 메서드(Collection 개체)