C# ArrayList的用法總結
System.Collections.ArrayList類是一個特殊的數組。通過添加和刪除元素,就可以動態改變數組的長度。
一、優點
1. 支持自動改變大小的功能
2. 可以靈活的插入元素
3. 可以靈活的刪除元素
4. 可以靈活訪問元素
二、局限性
跟一般的數組比起來,速度上差些
三、添加元素
1.public virtual int Add(object value);
將對象添加到ArrayList的結尾處
ArrayList aList=new ArrayList();
aList.Add("a");
aList.Add("b");
aList.Add("c");
aList.Add("d");
aList.Add("e");
內容為abcde
2.public virtual void Insert(int index,object value);
將元素插入ArrayList的指定索引處
ArrayList aList=new ArrayList();
aList.Add("a");
aList.Add("b");
aList.Add("c");
aList.Add("d");
aList.Add("e");
aList.Insert(0,"aa");
結果為aaabcde
3.public virtual void InsertRange(int index,ICollectionc);
將集合中的某個元素插入ArrayList的指定索引處
ArrayList aList=new ArrayList();
aList.Add("a");
aList.Add("b");
aList.Add("c");
aList.Add("d");
aList.Add("e");
ArrayList list2=new ArrayList();
list2.Add("tt");
list2.Add("ttt");
aList.InsertRange(2,list2);
結果為abtttttcde
四、刪除
1)public virtual void Remove(object obj);
從ArrayList中移除特定對象的第一個匹配項,注意是第一個
ArrayList aList=new ArrayList();
aList.Add("a");
aList.Add("b");
aList.Add("c");
aList.Add("d");
aList.Add("e");
aList.Remove("a");
結果為bcde
2.public virtual void RemoveAt(int index);
移除ArrayList的指定索引處的元素
aList.Add("a");
aList.Add("b");
aList.Add("c");
aList.Add("d");
aList.Add("e");
aList.RemoveAt(0);
結果為bcde
3.public virtual void RemoveRange(int index,int count);
從ArrayList中移除一定范圍的元素。Index表示索引,count表示從索引處開始的數目
aList.Add("a");
aList.Add("b");
aList.Add("c");
aList.Add("d");
aList.Add("e");
aList.RemoveRange(1,3);
結果為ae
4.public virtual void Clear();
從ArrayList中移除所有元素。
五、排序
1)public virtual void Sort();
對ArrayList或它的一部分中的元素進行排序。
ArrayLista List=new ArrayList();
aList.Add("e");
aList.Add("a");
aList.Add("b");
aList.Add("c");
aList.Add("d");
DropDownList1.DataSource=aList;//DropDown ListDropDownList1;
DropDownList1.DataBind();
結果為eabcd
ArrayList aList=new ArrayList();
aList.Add("a");
aList.Add("b");
aList.Add("c");
aList.Add("d");
aList.Add("e");
aList.Sort();//排序
DropDownList1.DataSource=aList;//DropDownListDropDownList1;
DropDownList1.DataBind();
結果為abcde
2)public virtual void Reverse();
將ArrayList或它的一部分中元素的順序反轉。
ArrayList aList=new ArrayList();
aList.Add("a");
aList.Add("b");
aList.Add("c");
aList.Add("d");
aList.Add("e");
aList.Reverse();//反轉
DropDownList1.DataSource=aList;//DropDownListDropDownList1;
DropDownList1.DataBind();
結果為edcba
六、查找
a)public virtual int IndexOf(object);
b)public virtual int IndexOf(object,int);
c)public virtual int IndexOf(object,int,int);
返回ArrayList或它的一部分中某個值的第一個匹配項的從零開始的索引。沒找到返回-1。
ArrayList aList=new ArrayList();
aList.Add("a");
aList.Add("b");
aList.Add("c");
aList.Add("d");
aList.Add("e");
intnIndex=aList.IndexOf(“a”);//1
nIndex=aList.IndexOf(“p”);//沒找到,-1
d)public virtual int LastIndexOf(object);
e)public virtual int LastIndexOf(object,int);
f)public virtual int LastIndexOf(object,int,int);
返回ArrayList或它的一部分中某個值的最后一個匹配項的從零開始的索引。
ArrayList aList=new ArrayList();
aList.Add("a");
aList.Add("b");
aList.Add("a");//同0
aList.Add("d");
aList.Add("e");
intnIndex=aList.LastIndexOf("a");//值為2而不是0
g)public virtual bool Contains(object item);
確定某個元素是否在ArrayList中。包含返回true,否則返回false
七、獲取數組中的元素
下面以整數為例,給出獲取某個元素的值的方法
ArrayList aList=new ArrayList();
for(int i=0;i<10;i++)
aList.Add(i);
for(i=0;i<10;i++)
Textbox1.text+=(int)aList[i]+" ";//獲取的方式基本與一般的數組相同,使用下標的方式進行
結果為:0 1 2 3 4 5 6 7 8 9
八、其他
1.public virtual int Capacity{get;set;}
獲取或設置ArrayList可包含的元素數。
2.public virtual int Count{get;}
獲取ArrayList中實際包含的元素數。
Capacity是ArrayList可以存儲的元素數。Count是ArrayList中實際包含的元素數。Capacity總是大於或等於Count。如果在添加元素時,Count超過Capacity,則該列表的容量會通過自動重新分配內部數組加倍。
如果Capacity的值顯式設置,則內部數組也需要重新分配以容納指定的容量。如果Capacity被顯式設置為0,則公共語言運行庫將其設置為默認容量。默認容量為16。
在調用Clear后,Count為0,而此時Capacity卻是默認容量16,而不是0
3.public virtual void TrimToSize();
將容量設置為ArrayList中元素的實際數量。
如果不向列表中添加新元素,則此方法可用於最小化列表的內存系統開銷。
若要完全清除列表中的所有元素,請在調用TrimToSize之前調用Clear方法。截去空ArrayList會將ArrayList的容量設置為默認容量,而不是零。
ArrayList aList=new ArrayList();
aList.Add("a");
aList.Add("b");
aList.Add("c");
aList.Add("d");
aList.Add("e");//Count=5,Capacity=16,
aList.TrimToSize();//Count=Capacity=5;
轉到自定義
#region 程序集 mscorlib.dll, v4.0.30319 // C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0\Profile\Client\mscorlib.dll #endregion using System; using System.Diagnostics; using System.Reflection; using System.Runtime; using System.Runtime.InteropServices; using System.Security; namespace System.Collections { // 摘要: // 使用大小可按需動態增加的數組實現 System.Collections.IList 接口。 [Serializable] [ComVisible(true)] [DebuggerTypeProxy(typeof(ArrayList.ArrayListDebugView))] [DebuggerDisplay("Count = {Count}")] public class ArrayList : IList, ICollection, IEnumerable, ICloneable { // 摘要: // 初始化 System.Collections.ArrayList 類的新實例,該實例為空並且具有默認初始容量。 [TargetedPatchingOptOut("Performance critical to inline across NGen image boundaries")] public ArrayList(); // // 摘要: // 初始化 System.Collections.ArrayList 類的新實例,該實例包含從指定集合復制的元素並且具有與所復制的元素數相同的初始容量。 // // 參數: // c: // System.Collections.ICollection,它的元素被復制到新列表中。 // // 異常: // System.ArgumentNullException: // c 為 null。 public ArrayList(ICollection c); // // 摘要: // 初始化 System.Collections.ArrayList 類的新實例,該實例為空並且具有指定的初始容量。 // // 參數: // capacity: // 新列表最初可以存儲的元素數。 // // 異常: // System.ArgumentOutOfRangeException: // capacity 小於零。 public ArrayList(int capacity); // 摘要: // 獲取或設置 System.Collections.ArrayList 可包含的元素數。 // // 返回結果: // System.Collections.ArrayList 可包含的元素數。 // // 異常: // System.ArgumentOutOfRangeException: // System.Collections.ArrayList.Capacity 設置為小於 System.Collections.ArrayList.Count // 的值。 // // System.OutOfMemoryException: // 系統中沒有足夠的可用內存。 public virtual int Capacity { get; set; } // // 摘要: // 獲取 System.Collections.ArrayList 中實際包含的元素數。 // // 返回結果: // System.Collections.ArrayList 中實際包含的元素數。 public virtual int Count { get; } // // 摘要: // 獲取一個值,該值指示 System.Collections.ArrayList 是否具有固定大小。 // // 返回結果: // 如果 System.Collections.ArrayList 具有固定大小,則為 true;否則為 false。默認值為 false。 public virtual bool IsFixedSize { get; } // // 摘要: // 獲取一個值,該值指示 System.Collections.ArrayList 是否為只讀。 // // 返回結果: // 如果 System.Collections.ArrayList 為只讀,則為 true;否則為 false。默認值為 false。 public virtual bool IsReadOnly { get; } // // 摘要: // 獲取一個值,該值指示是否同步對 System.Collections.ArrayList 的訪問(線程安全)。 // // 返回結果: // 如果對 System.Collections.ArrayList 的訪問是同步的(線程安全),則為 true;否則為 false。默認值為 false。 public virtual bool IsSynchronized { get; } // // 摘要: // 獲取可用於同步 System.Collections.ArrayList 訪問的對象。 // // 返回結果: // 可用於同步對 System.Collections.ArrayList 的訪問的對象。 public virtual object SyncRoot { get; } // 摘要: // 獲取或設置指定索引處的元素。 // // 參數: // index: // 要獲得或設置的元素從零開始的索引。 // // 返回結果: // 指定索引處的元素。 // // 異常: // System.ArgumentOutOfRangeException: // index 小於零。- 或 -index 等於或大於 System.Collections.ArrayList.Count。 public virtual object this[int index] { get; set; } // 摘要: // 為特定的 System.Collections.IList 創建 System.Collections.ArrayList 包裝。 // // 參數: // list: // 要包裝的 System.Collections.IList。 // // 返回結果: // System.Collections.IList 周圍的 System.Collections.ArrayList 包裝。 // // 異常: // System.ArgumentNullException: // list 為 null。 public static ArrayList Adapter(IList list); // // 摘要: // 將對象添加到 System.Collections.ArrayList 的結尾處。 // // 參數: // value: // 要添加到 System.Collections.ArrayList 的末尾處的 System.Object。該值可以為 null。 // // 返回結果: // System.Collections.ArrayList 索引,已在此處添加了 value。 // // 異常: // System.NotSupportedException: // System.Collections.ArrayList 是只讀的。- 或 -System.Collections.ArrayList 具有固定大小。 public virtual int Add(object value); // // 摘要: // 將 System.Collections.ICollection 的元素添加到 System.Collections.ArrayList 的末尾。 // // 參數: // c: // System.Collections.ICollection,其元素應被添加到 System.Collections.ArrayList 的末尾。集合本身不能為 // null,但它可以包含為 null 的元素。 // // 異常: // System.ArgumentNullException: // c 為 null。 // // System.NotSupportedException: // System.Collections.ArrayList 是只讀的。- 或 -System.Collections.ArrayList 具有固定大小。 [TargetedPatchingOptOut("Performance critical to inline across NGen image boundaries")] public virtual void AddRange(ICollection c); // // 摘要: // 使用默認的比較器在整個已排序的 System.Collections.ArrayList 中搜索元素,並返回該元素從零開始的索引。 // // 參數: // value: // 要定位的 System.Object。該值可以為 null。 // // 返回結果: // 如果找到 value,則為已排序的 System.Collections.ArrayList 中從零開始的 value 索引;否則為一個負數,它是大於 // value 的下一個元素索引的按位求補,如果沒有更大的元素,則為 System.Collections.ArrayList.Count 的按位求補。 // // 異常: // System.ArgumentException: // 無論是 value 還是 System.Collections.ArrayList 的元素都不實現 System.IComparable 接口。 // // System.InvalidOperationException: // value 與 System.Collections.ArrayList 的元素類型不同。 public virtual int BinarySearch(object value); // // 摘要: // 使用指定的比較器在整個已排序的 System.Collections.ArrayList 中搜索元素,並返回該元素從零開始的索引。 // // 參數: // value: // 要定位的 System.Object。該值可以為 null。 // // comparer: // 比較元素時要使用的 System.Collections.IComparer 實現。- 或 -null 表示使用默認比較器,即每個元素的 System.IComparable // 實現。 // // 返回結果: // 如果找到 value,則為已排序的 System.Collections.ArrayList 中從零開始的 value 索引;否則為一個負數,它是大於 // value 的下一個元素索引的按位求補,如果沒有更大的元素,則為 System.Collections.ArrayList.Count 的按位求補。 // // 異常: // System.ArgumentException: // comparer 為 null,而且 value 和 System.Collections.ArrayList 的元素都不實現 System.IComparable // 接口。 // // System.InvalidOperationException: // comparer 為 null,而且 value 與 System.Collections.ArrayList 的元素不屬於同一類型。 public virtual int BinarySearch(object value, IComparer comparer); // // 摘要: // 使用指定的比較器在已排序 System.Collections.ArrayList 的某個元素范圍中搜索元素,並返回該元素從零開始的索引。 // // 參數: // index: // 要搜索的范圍從零開始的起始索引。 // // count: // 要搜索的范圍的長度。 // // value: // 要定位的 System.Object。該值可以為 null。 // // comparer: // 比較元素時要使用的 System.Collections.IComparer 實現。- 或 -null 表示使用默認比較器,即每個元素的 System.IComparable // 實現。 // // 返回結果: // 如果找到 value,則為已排序的 System.Collections.ArrayList 中從零開始的 value 索引;否則為一個負數,它是大於 // value 的下一個元素索引的按位求補,如果沒有更大的元素,則為 System.Collections.ArrayList.Count 的按位求補。 // // 異常: // System.ArgumentException: // index 和 count 不表示 System.Collections.ArrayList 中的有效范圍。- 或 -comparer 為 null,而且 // value 和 System.Collections.ArrayList 的元素都不實現 System.IComparable 接口。 // // System.InvalidOperationException: // comparer 為 null,而且 value 與 System.Collections.ArrayList 的元素不屬於同一類型。 // // System.ArgumentOutOfRangeException: // index 小於零。- 或 -count 小於零。 public virtual int BinarySearch(int index, int count, object value, IComparer comparer); // // 摘要: // 從 System.Collections.ArrayList 中移除所有元素。 // // 異常: // System.NotSupportedException: // System.Collections.ArrayList 是只讀的。- 或 -System.Collections.ArrayList 具有固定大小。 public virtual void Clear(); // // 摘要: // 創建 System.Collections.ArrayList 的淺表副本。 // // 返回結果: // System.Collections.ArrayList 的淺表副本。 public virtual object Clone(); // // 摘要: // 確定某元素是否在 System.Collections.ArrayList 中。 // // 參數: // item: // 要在 System.Collections.ArrayList 中查找的 System.Object。該值可以為 null。 // // 返回結果: // 如果在 System.Collections.ArrayList 中找到 item,則為 true;否則為 false。 public virtual bool Contains(object item); // // 摘要: // 從目標數組的開頭開始將整個 System.Collections.ArrayList 復制到兼容的一維 System.Array 中。 // // 參數: // array: // 作為從 System.Collections.ArrayList 復制的元素的目標位置的一維 System.Array。System.Array // 必須具有從零開始的索引。 // // 異常: // System.ArgumentNullException: // array 為 null。 // // System.ArgumentException: // array 是多維數組。- 或 -源 System.Collections.ArrayList 中的元素數大於目標 array 可包含的元素數。 // // System.InvalidCastException: // 無法自動將源 System.Collections.ArrayList 的類型強制轉換為目標 array 的類型。 public virtual void CopyTo(Array array); // // 摘要: // 從目標數組的指定索引處開始將整個 System.Collections.ArrayList 復制到兼容的一維 System.Array。 // // 參數: // array: // 作為從 System.Collections.ArrayList 復制的元素的目標位置的一維 System.Array。System.Array // 必須具有從零開始的索引。 // // arrayIndex: // array 中從零開始的索引,將在此處開始復制。 // // 異常: // System.ArgumentNullException: // array 為 null。 // // System.ArgumentOutOfRangeException: // arrayIndex 小於零。 // // System.ArgumentException: // array 是多維數組。- 或 -源 System.Collections.ArrayList 中的元素數大於從 arrayIndex 到目標 array // 結尾處之間的可用空間。 // // System.InvalidCastException: // 無法自動將源 System.Collections.ArrayList 的類型強制轉換為目標 array 的類型。 public virtual void CopyTo(Array array, int arrayIndex); // // 摘要: // 從目標數組的指定索引處開始,將一定范圍的元素從 System.Collections.ArrayList 復制到兼容的一維 System.Array // 中。 // // 參數: // index: // 源 System.Collections.ArrayList 中復制開始位置的從零開始的索引。 // // array: // 作為從 System.Collections.ArrayList 復制的元素的目標位置的一維 System.Array。System.Array // 必須具有從零開始的索引。 // // arrayIndex: // array 中從零開始的索引,將在此處開始復制。 // // count: // 要復制的元素數。 // // 異常: // System.ArgumentNullException: // array 為 null。 // // System.ArgumentOutOfRangeException: // index 小於零。- 或 -arrayIndex 小於零。- 或 -count 小於零。 // // System.ArgumentException: // array 是多維數組。- 或 -index 等於或大於源 System.Collections.ArrayList 的 System.Collections.ArrayList.Count。- // 或 -從 index 到源 System.Collections.ArrayList 的末尾的元素數大於從 arrayIndex 到目標 array // 的末尾的可用空間。 // // System.InvalidCastException: // 無法自動將源 System.Collections.ArrayList 的類型強制轉換為目標 array 的類型。 public virtual void CopyTo(int index, Array array, int arrayIndex, int count); // // 摘要: // 返回具有固定大小的 System.Collections.ArrayList 包裝。 // // 參數: // list: // 要包裝的 System.Collections.ArrayList。 // // 返回結果: // 具有固定大小的 System.Collections.ArrayList 包裝。 // // 異常: // System.ArgumentNullException: // list 為 null。 public static ArrayList FixedSize(ArrayList list); // // 摘要: // 返回具有固定大小的 System.Collections.IList 包裝。 // // 參數: // list: // 要包裝的 System.Collections.IList。 // // 返回結果: // 具有固定大小的 System.Collections.IList 包裝。 // // 異常: // System.ArgumentNullException: // list 為 null。 public static IList FixedSize(IList list); // // 摘要: // 返回整個 System.Collections.ArrayList 的一個枚舉器。 // // 返回結果: // 用於整個 System.Collections.ArrayList 的 System.Collections.IEnumerator。 [TargetedPatchingOptOut("Performance critical to inline across NGen image boundaries")] public virtual IEnumerator GetEnumerator(); // // 摘要: // 返回 System.Collections.ArrayList 中某個范圍內的元素的枚舉器。 // // 參數: // index: // 枚舉器應引用的 System.Collections.ArrayList 部分從零開始的起始索引。 // // count: // 枚舉器應引用的 System.Collections.ArrayList 部分中的元素數。 // // 返回結果: // System.Collections.ArrayList 中指定范圍內的元素的 System.Collections.IEnumerator。 // // 異常: // System.ArgumentOutOfRangeException: // index 小於零。- 或 -count 小於零。 // // System.ArgumentException: // index 和 count 未指定 System.Collections.ArrayList 中的有效范圍。 [TargetedPatchingOptOut("Performance critical to inline across NGen image boundaries")] public virtual IEnumerator GetEnumerator(int index, int count); // // 摘要: // 返回 System.Collections.ArrayList,它表示源 System.Collections.ArrayList 中元素的子集。 // // 參數: // index: // 范圍開始處的從零開始的 System.Collections.ArrayList 索引。 // // count: // 范圍中的元素數。 // // 返回結果: // System.Collections.ArrayList,它表示源 System.Collections.ArrayList 中元素的子集。 // // 異常: // System.ArgumentOutOfRangeException: // index 小於零。- 或 -count 小於零。 // // System.ArgumentException: // index 和 count 不表示 System.Collections.ArrayList 中元素的有效范圍。 public virtual ArrayList GetRange(int index, int count); // // 摘要: // 搜索指定的 System.Object,並返回整個 System.Collections.ArrayList 中第一個匹配項的從零開始的索引。 // // 參數: // value: // 要在 System.Collections.ArrayList 中查找的 System.Object。該值可以為 null。 // // 返回結果: // 如果在整個 System.Collections.ArrayList 中找到 value 的第一個匹配項,則為該項的從零開始的索引;否則為 -1。 [TargetedPatchingOptOut("Performance critical to inline across NGen image boundaries")] public virtual int IndexOf(object value); // // 摘要: // 搜索指定的 System.Object,並返回 System.Collections.ArrayList 中從指定索引到最后一個元素的元素范圍內第一個匹配項的從零開始的索引。 // // 參數: // value: // 要在 System.Collections.ArrayList 中查找的 System.Object。該值可以為 null。 // // startIndex: // 從零開始的搜索的起始索引。空列表中 0(零)為有效值。 // // 返回結果: // 如果在 System.Collections.ArrayList 中從 startIndex 到最后一個元素的元素范圍內找到 value 的第一個匹配項,則為該項的從零開始的索引;否則為 // -1。 // // 異常: // System.ArgumentOutOfRangeException: // startIndex 不在 System.Collections.ArrayList 的有效索引范圍內。 public virtual int IndexOf(object value, int startIndex); // // 摘要: // 搜索指定的 System.Object,並返回 System.Collections.ArrayList 中從指定的索引開始並包含指定的元素數的元素范圍內第一個匹配項的從零開始的索引。 // // 參數: // value: // 要在 System.Collections.ArrayList 中查找的 System.Object。該值可以為 null。 // // startIndex: // 從零開始的搜索的起始索引。空列表中 0(零)為有效值。 // // count: // 要搜索的部分中的元素數。 // // 返回結果: // 如果在 System.Collections.ArrayList 中從 startIndex 開始並包含 count 個元素的元素范圍內找到 value // 的第一個匹配項,則為該項的從零開始的索引;否則為 -1。 // // 異常: // System.ArgumentOutOfRangeException: // startIndex 不在 System.Collections.ArrayList 的有效索引范圍內。- 或 -count 小於零。- 或 -startIndex // 和 count 未指定 System.Collections.ArrayList 中的有效部分。 public virtual int IndexOf(object value, int startIndex, int count); // // 摘要: // 將元素插入 System.Collections.ArrayList 的指定索引處。 // // 參數: // index: // 從零開始的索引,應在該位置插入 value。 // // value: // 要插入的 System.Object。該值可以為 null。 // // 異常: // System.ArgumentOutOfRangeException: // index 小於零。- 或 -index 大於 System.Collections.ArrayList.Count。 // // System.NotSupportedException: // System.Collections.ArrayList 是只讀的。- 或 -System.Collections.ArrayList 具有固定大小。 public virtual void Insert(int index, object value); // // 摘要: // 將集合中的某個元素插入 System.Collections.ArrayList 的指定索引處。 // // 參數: // index: // 應在此處插入新元素的從零開始的索引。 // // c: // System.Collections.ICollection,應將其元素插入到 System.Collections.ArrayList 中。集合本身不能為 // null,但它可以包含為 null 的元素。 // // 異常: // System.ArgumentNullException: // c 為 null。 // // System.ArgumentOutOfRangeException: // index 小於零。- 或 -index 大於 System.Collections.ArrayList.Count。 // // System.NotSupportedException: // System.Collections.ArrayList 是只讀的。- 或 -System.Collections.ArrayList 具有固定大小。 public virtual void InsertRange(int index, ICollection c); // // 摘要: // 搜索指定的 System.Object,並返回整個 System.Collections.ArrayList 中最后一個匹配項的從零開始的索引。 // // 參數: // value: // 要在 System.Collections.ArrayList 中查找的 System.Object。該值可以為 null。 // // 返回結果: // 如果在整個 System.Collections.ArrayList 中找到 value 的最后一個匹配項,則為該項的從零開始的索引;否則為 -1。 public virtual int LastIndexOf(object value); // // 摘要: // 搜索指定的 System.Object,並返回 System.Collections.ArrayList 中從第一個元素到指定索引的元素范圍內最后一個匹配項的從零開始的索引。 // // 參數: // value: // 要在 System.Collections.ArrayList 中查找的 System.Object。該值可以為 null。 // // startIndex: // 向后搜索的從零開始的起始索引。 // // 返回結果: // 如果在 System.Collections.ArrayList 中從第一個元素到 startIndex 的元素范圍內找到 value 的最后一個匹配項,則為該項的從零開始的索引;否則為 // -1。 // // 異常: // System.ArgumentOutOfRangeException: // startIndex 不在 System.Collections.ArrayList 的有效索引范圍內。 public virtual int LastIndexOf(object value, int startIndex); // // 摘要: // 搜索指定的 System.Object,並返回 System.Collections.ArrayList 中包含指定的元素數並在指定索引處結束的元素范圍內最后一個匹配項的從零開始的索引。 // // 參數: // value: // 要在 System.Collections.ArrayList 中查找的 System.Object。該值可以為 null。 // // startIndex: // 向后搜索的從零開始的起始索引。 // // count: // 要搜索的部分中的元素數。 // // 返回結果: // 如果在 System.Collections.ArrayList 中包含 count 個元素、在 startIndex 處結尾的元素范圍內找到 value // 的最后一個匹配項,則為該項的從零開始的索引;否則為 -1。 // // 異常: // System.ArgumentOutOfRangeException: // startIndex 不在 System.Collections.ArrayList 的有效索引范圍內。- 或 -count 小於零。- 或 -startIndex // 和 count 未指定 System.Collections.ArrayList 中的有效部分。 public virtual int LastIndexOf(object value, int startIndex, int count); // // 摘要: // 返回只讀的 System.Collections.ArrayList 包裝。 // // 參數: // list: // 要包裝的 System.Collections.ArrayList。 // // 返回結果: // list 周圍的只讀 System.Collections.ArrayList 包裝。 // // 異常: // System.ArgumentNullException: // list 為 null。 public static ArrayList ReadOnly(ArrayList list); // // 摘要: // 返回只讀的 System.Collections.IList 包裝。 // // 參數: // list: // 要包裝的 System.Collections.IList。 // // 返回結果: // list 周圍的只讀 System.Collections.IList 包裝。 // // 異常: // System.ArgumentNullException: // list 為 null。 public static IList ReadOnly(IList list); // // 摘要: // 從 System.Collections.ArrayList 中移除特定對象的第一個匹配項。 // // 參數: // obj: // 要從 System.Collections.ArrayList 移除的 System.Object。該值可以為 null。 // // 異常: // System.NotSupportedException: // System.Collections.ArrayList 是只讀的。- 或 -System.Collections.ArrayList 具有固定大小。 [TargetedPatchingOptOut("Performance critical to inline across NGen image boundaries")] public virtual void Remove(object obj); // // 摘要: // 移除 System.Collections.ArrayList 的指定索引處的元素。 // // 參數: // index: // 要移除的元素的從零開始的索引。 // // 異常: // System.ArgumentOutOfRangeException: // index 小於零。- 或 -index 等於或大於 System.Collections.ArrayList.Count。 // // System.NotSupportedException: // System.Collections.ArrayList 是只讀的。- 或 -System.Collections.ArrayList 具有固定大小。 public virtual void RemoveAt(int index); // // 摘要: // 從 System.Collections.ArrayList 中移除一定范圍的元素。 // // 參數: // index: // 要移除的元素的范圍從零開始的起始索引。 // // count: // 要移除的元素數。 // // 異常: // System.ArgumentOutOfRangeException: // index 小於零。- 或 -count 小於零。 // // System.ArgumentException: // index 和 count 不表示 System.Collections.ArrayList 中元素的有效范圍。 // // System.NotSupportedException: // System.Collections.ArrayList 是只讀的。- 或 -System.Collections.ArrayList 具有固定大小。 public virtual void RemoveRange(int index, int count); // // 摘要: // 返回 System.Collections.ArrayList,它的元素是指定值的副本。 // // 參數: // value: // 要在新 System.Collections.ArrayList 中對其進行多次復制的 System.Object。該值可以為 null。 // // count: // value 應被復制的次數。 // // 返回結果: // 具有 count 所指定的元素數的 System.Collections.ArrayList,其中的所有元素都是 value 的副本。 // // 異常: // System.ArgumentOutOfRangeException: // count 小於零。 public static ArrayList Repeat(object value, int count); // // 摘要: // 將整個 System.Collections.ArrayList 中元素的順序反轉。 // // 異常: // System.NotSupportedException: // System.Collections.ArrayList 是只讀的。 public virtual void Reverse(); // // 摘要: // 將指定范圍中元素的順序反轉。 // // 參數: // index: // 要反轉的范圍的從零開始的起始索引。 // // count: // 要反轉的范圍內的元素數。 // // 異常: // System.ArgumentOutOfRangeException: // index 小於零。- 或 -count 小於零。 // // System.ArgumentException: // index 和 count 不表示 System.Collections.ArrayList 中元素的有效范圍。 // // System.NotSupportedException: // System.Collections.ArrayList 是只讀的。 public virtual void Reverse(int index, int count); // // 摘要: // 將集合中的元素復制到 System.Collections.ArrayList 中一定范圍的元素上。 // // 參數: // index: // 從零開始的 System.Collections.ArrayList 索引,從該位置開始復制 c 的元素。 // // c: // System.Collections.ICollection,要將其元素復制到 System.Collections.ArrayList 中。集合本身不能為 // null,但它可以包含為 null 的元素。 // // 異常: // System.ArgumentOutOfRangeException: // index 小於零。- 或 -index 加上 c 中的元素數大於 System.Collections.ArrayList.Count。 // // System.ArgumentNullException: // c 為 null。 // // System.NotSupportedException: // System.Collections.ArrayList 是只讀的。 public virtual void SetRange(int index, ICollection c); // // 摘要: // 使用每個元素的 System.IComparable 實現對整個 System.Collections.ArrayList 中的元素進行排序。 // // 異常: // System.NotSupportedException: // System.Collections.ArrayList 是只讀的。 public virtual void Sort(); // // 摘要: // 使用指定的比較器對整個 System.Collections.ArrayList 中的元素進行排序。 // // 參數: // comparer: // 比較元素時要使用的 System.Collections.IComparer 實現。- 或 -null 引用(Visual Basic 中為 Nothing)將使用每個元數的 // System.IComparable 實現。 // // 異常: // System.NotSupportedException: // System.Collections.ArrayList 是只讀的。 public virtual void Sort(IComparer comparer); // // 摘要: // 使用指定的比較器對 System.Collections.ArrayList 中某個范圍內的元素進行排序。 // // 參數: // index: // 要排序的范圍的從零開始的起始索引。 // // count: // 要排序的范圍的長度。 // // comparer: // 比較元素時要使用的 System.Collections.IComparer 實現。- 或 -null 引用(Visual Basic 中為 Nothing)將使用每個元數的 // System.IComparable 實現。 // // 異常: // System.ArgumentOutOfRangeException: // index 小於零。- 或 -count 小於零。 // // System.ArgumentException: // index 和 count 未指定 System.Collections.ArrayList 中的有效范圍。 // // System.NotSupportedException: // System.Collections.ArrayList 是只讀的。 public virtual void Sort(int index, int count, IComparer comparer); // // 摘要: // 返回同步的(線程安全)System.Collections.ArrayList 包裝。 // // 參數: // list: // 要同步的 System.Collections.ArrayList。 // // 返回結果: // 同步的(線程安全)System.Collections.ArrayList 包裝。 // // 異常: // System.ArgumentNullException: // list 為 null。 public static ArrayList Synchronized(ArrayList list); // // 摘要: // 返回同步的(線程安全)System.Collections.IList 包裝。 // // 參數: // list: // 要同步的 System.Collections.IList。 // // 返回結果: // 同步的(線程安全)System.Collections.IList 包裝。 // // 異常: // System.ArgumentNullException: // list 為 null。 public static IList Synchronized(IList list); // // 摘要: // 將 System.Collections.ArrayList 的元素復制到新 System.Object 數組中。 // // 返回結果: // System.Object 數組,它包含 System.Collections.ArrayList 中元素的副本。 public virtual object[] ToArray(); // // 摘要: // 將 System.Collections.ArrayList 的元素復制到指定元素類型的新數組中。 // // 參數: // type: // 要創建並向其復制元素的目標數組的元素 System.Type。 // // 返回結果: // 指定元素類型的數組,它包含 System.Collections.ArrayList 中元素的副本。 // // 異常: // System.ArgumentNullException: // type 為 null。 // // System.InvalidCastException: // 源 System.Collections.ArrayList 的類型不能自動轉換為指定類型。 [SecuritySafeCritical] public virtual Array ToArray(Type type); // // 摘要: // 將容量設置為 System.Collections.ArrayList 中元素的實際數目。 // // 異常: // System.NotSupportedException: // System.Collections.ArrayList 是只讀的。- 或 -System.Collections.ArrayList 具有固定大小。 public virtual void TrimToSize(); } }