添加链接
link之家
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接
public ref class ArrayList : System::Collections::IList
public ref class ArrayList : ICloneable, System::Collections::IList
public class ArrayList : System.Collections.IList
public class ArrayList : ICloneable, System.Collections.IList
[System.Serializable]
public class ArrayList : ICloneable, System.Collections.IList
[System.Serializable]
[System.Runtime.InteropServices.ComVisible(true)]
public class ArrayList : ICloneable, System.Collections.IList
type ArrayList = class
    interface IEnumerable
    interface IList
    interface ICollection
type ArrayList = class
    interface ICollection
    interface IEnumerable
    interface IList
    interface ICloneable
type ArrayList = class
    interface IEnumerable
    interface IList
    interface ICollection
    interface ICloneable
[<System.Serializable>]
type ArrayList = class
    interface IList
    interface ICollection
    interface IEnumerable
    interface ICloneable
[<System.Serializable>]
[<System.Runtime.InteropServices.ComVisible(true)>]
type ArrayList = class
    interface IList
    interface ICollection
    interface IEnumerable
    interface ICloneable
Public Class ArrayList
Implements IList
Public Class ArrayList
Implements ICloneable, IList
ArrayList using namespace System; using namespace System::Collections; void PrintValues( IEnumerable^ myList ); int main() // Creates and initializes a new ArrayList. ArrayList^ myAL = gcnew ArrayList; myAL->Add( "Hello" ); myAL->Add( "World" ); myAL->Add( "!" ); // Displays the properties and values of the ArrayList. Console::WriteLine( "myAL" ); Console::WriteLine( " Count: {0}", myAL->Count ); Console::WriteLine( " Capacity: {0}", myAL->Capacity ); Console::Write( " Values:" ); PrintValues( myAL ); void PrintValues( IEnumerable^ myList ) IEnumerator^ myEnum = myList->GetEnumerator(); while ( myEnum->MoveNext() ) Object^ obj = safe_cast<Object^>(myEnum->Current); Console::Write( " {0}", obj ); Console::WriteLine(); This code produces output similar to the following: Count: 3 Capacity: 4 Values: Hello World ! using System; using System.Collections; public class SamplesArrayList { public static void Main() { // Creates and initializes a new ArrayList. ArrayList myAL = new ArrayList(); myAL.Add("Hello"); myAL.Add("World"); myAL.Add("!"); // Displays the properties and values of the ArrayList. Console.WriteLine( "myAL" ); Console.WriteLine( " Count: {0}", myAL.Count ); Console.WriteLine( " Capacity: {0}", myAL.Capacity ); Console.Write( " Values:" ); PrintValues( myAL ); public static void PrintValues( IEnumerable myList ) { foreach ( Object obj in myList ) Console.Write( " {0}", obj ); Console.WriteLine(); This code produces output similar to the following: Count: 3 Capacity: 4 Values: Hello World ! Imports System.Collections Public Class SamplesArrayList Public Shared Sub Main() ' Creates and initializes a new ArrayList. Dim myAL As New ArrayList() myAL.Add("Hello") myAL.Add("World") myAL.Add("!") ' Displays the properties and values of the ArrayList. Console.WriteLine("myAL") Console.WriteLine(" Count: {0}", myAL.Count) Console.WriteLine(" Capacity: {0}", myAL.Capacity) Console.Write(" Values:") PrintValues(myAL) End Sub Public Shared Sub PrintValues(myList As IEnumerable) Dim obj As [Object] For Each obj In myList Console.Write(" {0}", obj) Next obj Console.WriteLine() End Sub End Class ' This code produces output similar to the following: ' myAL ' Count: 3 ' Capacity: 4 ' Values: Hello World !

不建議您將 類別用於 ArrayList 新的開發。 相反地,建議您使用泛型 List<T> 類別。 類別 ArrayList 的設計目的是要保存物件的異質集合。 不過,它不一定會提供最佳效能。 相反地,我們建議使用下列專案:

  • 如果是對象的異質集合,請使用 List<Object> C#) 中的 (,或在 List(Of Object) Visual Basic) 類型中使用 (。
  • 針對物件的同質集合,請使用 類別 List<T> 。 如需這些類別相對效能的討論,請參閱參考主題中的 List<T> 效能考慮 。 如需 使用泛型 而非非泛型集合類型的一般資訊,請參閱不應在 GitHub 上使用非泛型集合。
  • ArrayList 不保證會排序 。 ArrayList 您必須先呼叫 其 Sort 方法,才能執行 (,例如 BinarySearch 需要 ArrayList 排序 的) 。 若要維護自動排序為加入新元素的集合,您可以使用 SortedSet<T> 類別。

    ArrayList 容量是 可以保留的項目 ArrayList 數目。 隨著元素新增至 ArrayList ,容量會自動隨著重新配置而增加。 您可以藉由呼叫 TrimToSize 或明確設定 Capacity 屬性來減少容量。

    僅限 .NET Framework: 對於非常大 ArrayList 的物件,您可以在運行時間環境中將組態專案的 屬性 <gcAllowVeryLargeObjects> 設定 enabled true ,將 64 位系統上的最大容量增加到 20 億個專案。

    此集合中的專案可以使用整數索引來存取。 此集合中的索引是以零起始。

    集合 ArrayList 接受 null 做為有效值。 它也允許重複的專案。

    不支援使用多維度陣列作為集合中的 ArrayList 專案。

    執行緒安全性

    Visual Basic 中的公用靜態 ( Shared ) 此類型的成員是安全線程。 並非所有的執行個體成員都是安全執行緒。

    ArrayList 可以同時支援多個讀取器,只要集合未修改即可。 若要保證的 ArrayList 線程安全性,所有作業都必須透過 方法傳 Synchronized(IList) 回的包裝函式來完成。

    透過集合進行列舉在本質上並非安全執行緒程序。 即使集合經過同步化,其他的執行緒仍可修改該集合,使列舉值擲回例外狀況。 若要保證列舉過程的執行緒安全,您可以在整個列舉過程中鎖定集合,或攔截由其他執行緒的變更所造成的例外狀況。

  • IList
  • List<T>
  • 在集合中執行 Culture-Insensitive 字串作業
  • 即將登場:在 2024 年,我們將逐步淘汰 GitHub 問題作為內容的意見反應機制,並將它取代為新的意見反應系統。 如需詳細資訊,請參閱: https://aka.ms/ContentUserFeedback

    提交並檢視相關的意見反應