OrderedDictionary.Contains(Object) メソッド
定義
重要
一部の情報は、リリース前に大きく変更される可能性があるプレリリースされた製品に関するものです。 Microsoft は、ここに記載されている情報について、明示または黙示を問わず、一切保証しません。
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 コレクション内で検索されるキー。
戻り値
指定したキーを持つ要素が 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して行われました。