OrderedDictionary.IsReadOnly Propiedad

Definición

Obtiene un valor que indica si la colección OrderedDictionary es de solo lectura.

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

Valor de propiedad

true si la colección OrderedDictionary es de sólo lectura; en caso contrario, false. De manera predeterminada, es false.

Implementaciones

Ejemplos

En el ejemplo de código siguiente se muestra la modificación de una OrderedDictionary colección. En este ejemplo, la IsReadOnly propiedad se usa para determinar si OrderedDictionary se puede modificar . Este código forma parte de un ejemplo de código más grande que se puede ver en 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

Comentarios

Una colección de solo lectura no permite que se agreguen, quiten o modifiquen elementos una vez que se ha creado.

Una colección que es de solo lectura es simplemente una colección con un contenedor que impide la modificación de la colección; por lo tanto, si se realizan cambios en la colección subyacente, la colección de solo lectura refleja esos cambios.

Se aplica a