ICollection<T>.Remove(T) 方法

定义

ICollection<T> 中移除特定对象的第一个匹配项。Removes the first occurrence of a specific object from the ICollection<T>.

public:
 bool Remove(T item);
public bool Remove (T item);
abstract member Remove : 'T -> bool
Public Function Remove (item As T) As Boolean

参数

item
T

要从 ICollection<T> 中删除的对象。The object to remove from the ICollection<T>.

返回

Boolean

如果从 true 中成功移除 item,则为 ICollection<T>;否则为 falsetrue if item was successfully removed from the ICollection<T>; otherwise, false. 如果在原始 false 中没有找到 item,该方法也会返回 ICollection<T>This method also returns false if item is not found in the original ICollection<T>.

例外

ICollection<T> 为只读。The ICollection<T> is read-only.

注解

在如何确定对象是否相等方面这些实现可能存在差异;例如,List<T> 使用 Comparer<T>.Default,而 Dictionary<TKey,TValue> 允许用户指定 IComparer<T> 实现以用来对键进行比较。Implementations can vary in how they determine equality of objects; for example, List<T> uses Comparer<T>.Default, whereas, Dictionary<TKey,TValue> allows the user to specify the IComparer<T> implementation to use for comparing keys.

在由连续的元素组成的集合(如列表)中,已移除元素下面的元素将上移以占据空出的位置。In collections of contiguous elements, such as lists, the elements that follow the removed element move up to occupy the vacated spot. 如果集合具有索引,则移动的元素的索引也将更新。If the collection is indexed, the indexes of the elements that are moved are also updated. 此行为不适用于元素按概念划分为不同存储桶的集合,如哈希表。This behavior does not apply to collections where elements are conceptually grouped into buckets, such as a hash table.

适用于

另请参阅