OrderedDictionary.Add(Object, Object) Método
Definição
Importante
Algumas informações dizem respeito a um produto pré-lançado que pode ser substancialmente modificado antes de ser lançado. A Microsoft não faz garantias, de forma expressa ou implícita, em relação à informação aqui apresentada.
Adiciona uma entrada com a chave e valor especificados à OrderedDictionary coleção com o índice mais baixo disponível.
public:
virtual void Add(System::Object ^ key, System::Object ^ value);
public void Add(object key, object value);
public void Add(object key, object? value);
abstract member Add : obj * obj -> unit
override this.Add : obj * obj -> unit
Public Sub Add (key As Object, value As Object)
Parâmetros
- key
- Object
A chave da entrada para acrescentar.
- value
- Object
O valor da entrada a acrescentar. Este valor pode ser null.
Implementações
Exceções
A OrderedDictionary coleção é apenas de leitura.
Já existe um elemento com a mesma chave na OrderedDictionary coleção.
Exemplos
O exemplo de código seguinte demonstra a criação e população de uma OrderedDictionary coleção. Este código faz parte de um exemplo de código maior que pode ser visto em OrderedDictionary.
// Creates and initializes a OrderedDictionary.
OrderedDictionary myOrderedDictionary = new OrderedDictionary();
myOrderedDictionary.Add("testKey1", "testValue1");
myOrderedDictionary.Add("testKey2", "testValue2");
myOrderedDictionary.Add("keyToDelete", "valueToDelete");
myOrderedDictionary.Add("testKey3", "testValue3");
ICollection keyCollection = myOrderedDictionary.Keys;
ICollection valueCollection = myOrderedDictionary.Values;
// Display the contents using the key and value collections
DisplayContents(keyCollection, valueCollection, myOrderedDictionary.Count);
' Creates and initializes a OrderedDictionary.
Dim myOrderedDictionary As New OrderedDictionary()
myOrderedDictionary.Add("testKey1", "testValue1")
myOrderedDictionary.Add("testKey2", "testValue2")
myOrderedDictionary.Add("keyToDelete", "valueToDelete")
myOrderedDictionary.Add("testKey3", "testValue3")
Dim keyCollection As ICollection = myOrderedDictionary.Keys
Dim valueCollection As ICollection = myOrderedDictionary.Values
' Display the contents Imports the key and value collections
DisplayContents( _
keyCollection, valueCollection, myOrderedDictionary.Count)
Observações
Uma chave não pode ser null, mas um valor pode ser.
Também pode usar a Item[] propriedade para adicionar novos elementos definindo o valor de uma chave que não existe na OrderedDictionary coleção; no entanto, se a chave especificada já existir na OrderedDictionary, a Item[] definição da propriedade sobrescreve o valor antigo. Em contraste, o Add método não modifica elementos existentes, mas sim lança ArgumentException.