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>.

傳回

如果 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. 集合的項目若在概念上群組成 Bucket (例如雜湊資料表),則不適用這項行為。This behavior does not apply to collections where elements are conceptually grouped into buckets, such as a hash table.

適用於

另請參閱