次の方法で共有


OrderedDictionary.IsReadOnly プロパティ

定義

OrderedDictionary コレクションが読み取り専用かどうかを示す値を取得します。

public:
 property bool IsReadOnly { bool get(); };
public bool IsReadOnly { get; }
member this.IsReadOnly : bool
Public ReadOnly Property IsReadOnly As Boolean

プロパティ値

true OrderedDictionary コレクションが読み取り専用の場合は >。それ以外の場合はfalse。 既定値は、false です。

実装

次のコード例は、 OrderedDictionary コレクションの変更を示しています。 この例では、 IsReadOnly プロパティを使用して、 OrderedDictionary を変更できるかどうかを判断します。 このコードは、 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

注釈

読み取り専用のコレクションでは、コレクションの作成後に要素を追加、削除、または変更することはできません。

読み取り専用のコレクションは、コレクションの変更を防ぐラッパーを持つコレクションです。したがって、基になるコレクションに変更が加えられた場合、読み取り専用コレクションにはそれらの変更が反映されます。

適用対象