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 컬렉션에서 찾을 키입니다.

반환

Boolean

OrderedDictionary 컬렉션에 지정한 키가 있는 요소가 포함된 경우 true이고, 그렇지 않으면 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 (!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 .

.NET Framework 2.0부터 이 메서드는 컬렉션의 개체 EqualsCompareTo 메서드 item 를 사용하여 존재하는지 여부를 item 확인합니다. 이전 버전의 .NET Framework 컬렉션에 있는 개체에 Equals 대한 매개 변수의 메서드와 CompareTo 매개 변수를 item 사용하여 이 결정을 내렸습니다.

적용 대상