ICollection<T>.Remove(T) 方法

定義

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> 移除的物件。

傳回

如果 true 已成功從 item 中移除,則為 ICollection<T>,否則為 false。 如果在原本的 false 中找不到 item,則這個方法也會傳回 ICollection<T>

例外狀況

備註

實作依判斷物件相等的方法會有所不同;例如,List<T> 使用 Comparer<T>.Default,而 Dictionary<TKey,TValue> 則讓使用者指定要用來比較索引鍵的 IComparer<T> 實作。

在相鄰元素的集合中,例如清單,接在移除的元素之後的元素會向上移動以佔用空出的位置。 如果集合具有索引,則移動之項目的索引也會更新。 集合的項目若在概念上群組成 Bucket (例如雜湊資料表),則不適用這項行為。

適用於

另請參閱