SortedSet<T>.Add(T) 方法

定義

將項目加入至資料集,並傳回表示是否成功加入的值。Adds an element to the set and returns a value that indicates if it was successfully added.

public:
 virtual bool Add(T item);
public bool Add (T item);
abstract member Add : 'T -> bool
override this.Add : 'T -> bool
Public Function Add (item As T) As Boolean

參數

item
T

要加入至集合的項目。The element to add to the set.

傳回

Boolean

如果 item 已加入至資料集,則為 true,否則為 falsetrue if item is added to the set; otherwise, false.

實作

範例

下列範例會將元素加入至已排序的集合。The following example adds elements to a sorted set. 這個程式碼範例是針對類別提供之較大範例的一部分 SortedSet<T>This code example is part of a larger example provided for the SortedSet<T> class.

foreach (string f in files1)
{
    mediaFiles1.Add(f.Substring(f.LastIndexOf(@"\") + 1));
}
For Each f As String In files1
    mediaFiles1.Add(f.Substring((f.LastIndexOf("\") + 1)))
Next

備註

SortedSet<T>類別不接受重複的專案。The SortedSet<T> class does not accept duplicate elements. 如果 item 已經在集合中,這個方法會傳回, false 而且不會擲回例外狀況。If item is already in the set, this method returns false and does not throw an exception.

如果 Count 已等於物件的容量 SortedSet<T> ,則會自動調整容量以容納新專案。If Count already equals the capacity of the SortedSet<T> object, the capacity is automatically adjusted to accommodate the new item.

適用於