OrderedDictionary.Contains(Object) 메서드

정의

컬렉션에 OrderedDictionary 특정 키가 포함되어 있는지 여부를 확인합니다.

public:
 virtual bool Contains(System::Object ^ key);
public bool Contains(object key);
abstract member Contains : obj -> bool
override this.Contains : obj -> bool
Public Function Contains (key As Object) As Boolean

매개 변수

key
Object

컬렉션에서 찾을 키입니다 OrderedDictionary .

반품

true 컬렉션에 OrderedDictionary 지정된 키가 있는 요소가 포함되어 있으면 이고, false그렇지 않으면 .

구현

예제

다음 코드 예제에서는 컬렉션의 수정을 보여 줍니다 OrderedDictionary . 이 예제 Contains 에서 메서드는 항목을 제거하기 전에 항목이 있는지 확인하는 데 사용됩니다. 이 코드는 에서 OrderedDictionary볼 수 있는 더 큰 코드 예제의 일부입니다.

// Modifying the OrderedDictionary
if (!myOrderedDictionary.IsReadOnly)
{
    // Insert a new key to the beginning of the OrderedDictionary
    myOrderedDictionary.Insert(0, "insertedKey1", "insertedValue1");

    // Modify the value of the entry with the key "testKey2"
    myOrderedDictionary["testKey2"] = "modifiedValue";

    // Remove the last entry from the OrderedDictionary: "testKey3"
    myOrderedDictionary.RemoveAt(myOrderedDictionary.Count - 1);

    // Remove the "keyToDelete" entry, if it exists
    if (myOrderedDictionary.Contains("keyToDelete"))
    {
        myOrderedDictionary.Remove("keyToDelete");
    }
}
' Modifying the OrderedDictionary
If Not myOrderedDictionary.IsReadOnly Then

    ' Insert a new key to the beginning of the OrderedDictionary
    myOrderedDictionary.Insert(0, "insertedKey1", "insertedValue1")

    ' Modify the value of the entry with the key "testKey2"
    myOrderedDictionary("testKey2") = "modifiedValue"

    ' Remove the last entry from the OrderedDictionary: "testKey3"
    myOrderedDictionary.RemoveAt(myOrderedDictionary.Count - 1)

    ' Remove the "keyToDelete" entry, if it exists
    If (myOrderedDictionary.Contains("keyToDelete")) Then
        myOrderedDictionary.Remove("keyToDelete")
    End If
End If

설명

Item[] 키가 없거나 키가 있는 경우 속성을 사용하면 null 값을 반환할 수 있습니다null. 메서드를 Contains 사용하여 컬렉션에 특정 키가 있는지 확인합니다 OrderedDictionary .

이 메서드는 컬렉션의 개체 Equals 와 메서드를 item 사용하여 존재하는지 여부를 item 확인 CompareTo 합니다.

적용 대상