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 以降では、このメソッドはコレクションのオブジェクトEqualsとメソッドをitem使用して存在するかどうかをitem判断CompareToします。 以前のバージョンの.NET Frameworkでは、この決定は、コレクション内のitemオブジェクトのパラメーターとCompareToメソッドを使用してEquals行われました。

適用対象