CollectionBase.OnClear 方法

定义

清除 CollectionBase 实例的内容时执行其他自定义进程。Performs additional custom processes when clearing the contents of the CollectionBase instance.

protected:
 virtual void OnClear();
protected virtual void OnClear ();
abstract member OnClear : unit -> unit
override this.OnClear : unit -> unit
Protected Overridable Sub OnClear ()

注解

此方法的默认实现旨在由派生类重写,以在清除集合之前执行某些操作。The default implementation of this method is intended to be overridden by a derived class to perform some action before the collection is cleared.

On * 方法仅在 List 属性返回的实例上调用,而不是在 InnerList 属性返回的实例上调用。The On* methods are invoked only on the instance returned by the List property, but not on the instance returned by the InnerList property.

如果进程失败,则集合恢复为其以前的状态。If the process fails, the collection reverts back to its previous state.

此方法的默认实现是 O(1) 操作。The default implementation of this method is an O(1) operation.

继承者说明

此方法允许实施者定义在从基础 ArrayList删除所有元素之前必须执行的过程。This method allows implementers to define processes that must be performed before deleting all the elements from the underlying ArrayList. 通过定义此方法,实施者可以向继承的方法添加功能,而无需重写所有其他方法。By defining this method, implementers can add functionality to inherited methods without having to override all other methods.

OnClear() 在标准清除行为之前调用,而 OnClearComplete() 则在标准清楚行为之后调用。OnClear() is invoked before the standard Clear behavior, whereas OnClearComplete() is invoked after the standard Clear behavior.

例如,实施者可以通过全局明文免除某些元素删除。For example, implementers can exempt certain elements from deletion by a global Clear.

适用于

另请参阅