OrderedDictionary.Remove(Object) Метод
Определение
Удаляет запись с указанным ключом из коллекции OrderedDictionary.Removes the entry with the specified key from the OrderedDictionary collection.
public:
virtual void Remove(System::Object ^ key);
public void Remove (object key);
abstract member Remove : obj -> unit
override this.Remove : obj -> unit
Public Sub Remove (key As Object)
Параметры
- key
- Object
Ключ записи, которую требуется удалить.The key of the entry to remove.
Реализации
Исключения
Коллекция OrderedDictionary доступна только для чтения.The OrderedDictionary collection is read-only.
key
имеет значение null
.key
is null
.
Примеры
В следующем примере кода показано изменение OrderedDictionary коллекции.The following code example demonstrates the modification of an OrderedDictionary collection. В этом примере Remove метод используется для удаления записи с ключом "keyToDelete"
из OrderedDictionary .In this example, the Remove method is used to remove the entry with the key "keyToDelete"
from the OrderedDictionary. Этот код является частью более крупного примера кода, который можно просмотреть по адресу OrderedDictionary .This code is part of a larger code example that can be viewed at 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
Комментарии
Записи, которые следуют за удаленной записью, перемещаются вверх, чтобы занимать освободившееся место, а также обновляются индексы записей, которые перемещаются.The entries that follow the removed entry move up to occupy the vacated spot and the indexes of the entries that move are also updated.
Если OrderedDictionary коллекция не содержит запись с указанным ключом, значение OrderedDictionary остается неизменным и исключение не создается.If the OrderedDictionary collection does not contain an entry with the specified key, the OrderedDictionary remains unchanged and no exception is thrown.