ArrayList 建構函式
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
初始化 ArrayList 類別的新執行個體。
多載
| 名稱 | Description |
|---|---|
| ArrayList() |
初始化一個空且預設初始容量的類別實例 ArrayList 。 |
| ArrayList(ICollection) |
初始化 ArrayList 類別的新實例,這個實例包含從指定的集合複製的專案,且其初始容量與複製的項目數目相同。 |
| ArrayList(Int32) |
初始化 ArrayList 類別的新實例,這個實例是空的,而且具有指定的初始容量。 |
ArrayList()
- 來源:
- ArrayList.cs
- 來源:
- ArrayList.cs
- 來源:
- ArrayList.cs
- 來源:
- ArrayList.cs
- 來源:
- ArrayList.cs
初始化一個空且預設初始容量的類別實例 ArrayList 。
public:
ArrayList();
public ArrayList();
Public Sub New ()
備註
一個 ArrayList 的容量是它 ArrayList 能容納的元素數量。 當元素加入 時 ArrayList,容量會自動根據需要重新配置內部陣列而增加。
若能估計集合的大小,指定初始容量即可免除在加入元素 ArrayList時進行多次調整大小操作的需求。
這個建構子是一個 O(1) 運算。
另請參閱
適用於
ArrayList(ICollection)
- 來源:
- ArrayList.cs
- 來源:
- ArrayList.cs
- 來源:
- ArrayList.cs
- 來源:
- ArrayList.cs
- 來源:
- ArrayList.cs
初始化 ArrayList 類別的新實例,這個實例包含從指定的集合複製的專案,且其初始容量與複製的項目數目相同。
public:
ArrayList(System::Collections::ICollection ^ c);
public ArrayList(System.Collections.ICollection c);
new System.Collections.ArrayList : System.Collections.ICollection -> System.Collections.ArrayList
Public Sub New (c As ICollection)
參數
其 ICollection 元素會被複製到新清單中。
例外狀況
c 為 null。
c 是一個多維陣列。
備註
一個 ArrayList 的容量是它 ArrayList 能容納的元素數量。 當元素加入 時 ArrayList,容量會自動根據需要重新配置內部陣列而增加。
若能估計集合的大小,指定初始容量即可免除在加入元素 ArrayList時進行多次調整大小操作的需求。
元素被複製到,ArrayList順序與讀取相同的順序IEnumeratorICollection。
此構造子是一個 O(n) 運算,其中 n 是 中的 c元素數量。
另請參閱
適用於
ArrayList(Int32)
- 來源:
- ArrayList.cs
- 來源:
- ArrayList.cs
- 來源:
- ArrayList.cs
- 來源:
- ArrayList.cs
- 來源:
- ArrayList.cs
初始化 ArrayList 類別的新實例,這個實例是空的,而且具有指定的初始容量。
public:
ArrayList(int capacity);
public ArrayList(int capacity);
new System.Collections.ArrayList : int -> System.Collections.ArrayList
Public Sub New (capacity As Integer)
參數
- capacity
- Int32
新清單最初可儲存的元素數量。
例外狀況
capacity 小於零。
備註
一個 ArrayList 的容量是它 ArrayList 能容納的元素數量。 當元素加入 時 ArrayList,容量會自動根據需要重新配置內部陣列而增加。
若能估計集合的大小,指定初始容量即可免除在加入元素 ArrayList時進行多次調整大小操作的需求。
此構造子是一個 O(n) 運算,其中 n 為 capacity。
謹慎
如果是 capacity 使用者輸入,建議使用無參數建構器,並讓集合隨著元素加入而調整大小。 如果必須使用使用者指定的值,要麼將其限制在合理範圍內(例如 Math.Clamp(untrustedValue, 0, 20)),要麼驗證元素數量是否符合指定值。