Compartilhar via


OrderedDictionary.IsReadOnly Propriedade

Definição

Obtém um valor que indica se a OrderedDictionary coleção é somente leitura.

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

Valor da propriedade

true se a OrderedDictionary coleção for somente leitura; caso contrário, false. O padrão é false.

Implementações

Exemplos

O exemplo de código a seguir demonstra a modificação de uma OrderedDictionary coleção. Neste exemplo, a IsReadOnly propriedade é usada para determinar se ela OrderedDictionary pode ser modificada. Esse código faz parte de um exemplo de código maior que pode ser exibido em 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

Comentários

Uma coleção somente leitura não permite a adição, remoção ou modificação de elementos após a criação da coleção.

Uma coleção somente leitura é simplesmente uma coleção com um wrapper que impede a modificação da coleção; portanto, se forem feitas alterações na coleção subjacente, a coleção somente leitura refletirá essas alterações.

Aplica-se a