Bagikan melalui


OrderedDictionary.IsReadOnly Properti

Definisi

Mendapatkan nilai yang menunjukkan apakah OrderedDictionary koleksi bersifat baca-saja.

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

Nilai Properti

trueOrderedDictionary jika koleksi bersifat baca-saja; jika tidak, false. Default adalah false.

Penerapan

Contoh

Contoh kode berikut menunjukkan modifikasi OrderedDictionary koleksi. Dalam contoh ini, IsReadOnly properti digunakan untuk menentukan apakah OrderedDictionary dapat dimodifikasi. Kode ini adalah bagian dari contoh kode yang lebih besar yang dapat dilihat di 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

Keterangan

Koleksi yang bersifat baca-saja tidak mengizinkan penambahan, penghapusan, atau modifikasi elemen setelah koleksi dibuat.

Koleksi yang bersifat baca-saja hanyalah koleksi dengan pembungkus yang mencegah modifikasi koleksi; oleh karena itu, jika perubahan dilakukan pada koleksi yang mendasar, koleksi baca-saja mencerminkan perubahan tersebut.

Berlaku untuk