C# ArrayList的用法总结

时间:2022-09-02 07:29:55

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();
}
}

C# ArrayList的用法总结的更多相关文章

  1. C&num; ArrayList的用法

    System.Collections.ArrayList类是一个特殊的数组.通过添加和删除元素,就可以动态改变数组的长度. 一.优点 1. 支持自动改变大小的功能 2. 可以灵活的插入元素 3. 可以 ...

  2. C&num; ArrayList 基本用法 分类: C&num; 2014-09-26 11&colon;03 524人阅读 评论&lpar;0&rpar; 收藏

    首先说明一下ArrayList 与 数组的区别: (1)ArrayList 的容量可以根据需要*扩充,数组的容量是固定的 (2)ArrayList 只能是一维形式,数组可以是多维的 (3)Array ...

  3. Java学习笔记之ArrayList基本用法

    原文地址,转载请注明出处:https://blog.csdn.net/GongchuangSu/article/details/51514389 ArrayList简介 ArrayList是一个其容量 ...

  4. ArrayList用法详解与源码分析

    说明 此文章分两部分,1.ArrayList用法.2.源码分析.先用法后分析是为了以后忘了查阅起来方便-- ArrayList 基本用法 1.创建ArrayList对象 //创建默认容量的数组列表(默 ...

  5. 计算机程序的思维逻辑 &lpar;38&rpar; - 剖析ArrayList

    从本节开始,我们探讨Java中的容器类,所谓容器,顾名思义就是容纳其他数据的,计算机课程中有一门课叫数据结构,可以粗略对应于Java中的容器类,我们不会介绍所有数据结构的内容,但会介绍Java中的主要 ...

  6. ArrayList&comma;Vector&comma;LinkedList

    在java.util包中定义的类集框架其核心的组成接口有如下:·Collection接口:负责保存单值的最大父接口 |-List子接口:允许保存重复元素,数据的保存顺序就是数据的增加顺序: |-Set ...

  7. vector在C&plus;&plus;中的基本用法

    在写BlackJackGame的时候,考虑到要用到容器,所以就对容器的相关知识强化了一下: 因为我想的是有card类,最后要实现发牌,洗牌等等一系列的操作的时候,使用指向card类的对象的指针,将ca ...

  8. c&num;重点&lbrack;集合类型&rsqb;异常&comma;数组,集合ArrayList&comma;List&lt&semi;&gt&semi;&comma;hashTable&comma;hashtable泛型&lpar;Dictionary&rpar;

    1.foreach[对一些数组或集合进行遍历] foreach(类型 变量名 in 集合对象){语句体} //定义一个数组 ,,,,, }; foreach(var i in sNum1) { Con ...

  9. 编写测试类,了解ArrayList的方法

    这篇文章主要介绍了C#中动态数组用法,实例分析了C#中ArrayList实现动态数组的技巧,非常具有实用价值,需要的朋友可以参考下 本文实例讲述了C#中动态数组用法.分享给大家供大家参考.具体分析如下 ...

随机推荐

  1. ELK&plus;FileBeat&plus;Log4Net

    ELK+FileBeat+Log4Net搭建日志系统 output { elasticsearch { hosts => ["localhost:9200"] } stdou ...

  2. 在VS2012中编译WinXP兼容的程序

    VS2012默认是不兼容Windows XP的,编译链接出来的程序只能在Windows Vista及以上版本的操作系统上运行.可是有时需要在Windows XP上运行,又不得不用VS2012(例如用了 ...

  3. Java&comma;Calendar 获得明天凌晨的时间time

    /** * 获得明天凌晨的时间time * * @return */ private long getNextDayZeroTime() { Calendar calendar = Calendar. ...

  4. apache泛域名的配置

    假设我们把服务器架设在:/home/www文件夹下面 我们有应用A和B,对应的文件目录为A:/home/www/testAB:/home/www/testB 设置proxy_module让网站支持泛域 ...

  5. lightOJ1370 欧拉函数性质

    D - (例题)欧拉函数性质 Crawling in process... Crawling failed Time Limit:2000MS     Memory Limit:32768KB     ...

  6. Altium designer使用技巧集(1)

    1.如何生成PCB 先得新建个PCB文件(File-New-Pcb):然后保存下,在新建的PCB文件下:Design-Import Changes From PCB_PROJECT1.PRJPCB(D ...

  7. 【NLP】3000篇搜狐新闻语料数据预处理器的python实现

    3000篇搜狐新闻语料数据预处理器的python实现 白宁超 2017年5月5日17:20:04 摘要: 关于自然语言处理模型训练亦或是数据挖掘.文本处理等等,均离不开数据清洗,数据预处理的工作.这里 ...

  8. android Intent机制详解

    http://www.oschina.net/question/565065_67909 http://www.cnblogs.com/hummersofdie/archive/2011/02/12/ ...

  9. 第十五节:深入理解async和await的作用及各种适用场景和用法

    一. 同步VS异步 1.   同步 VS 异步 VS 多线程 同步方法:调用时需要等待返回结果,才可以继续往下执行业务 异步方法:调用时无须等待返回结果,可以继续往下执行业务 开启新线程:在主线程之外 ...

  10. SQL注入之Sqli-labs系列第二关

    废话不在多说  let's go!   继续挑战第二关(Error Based- Intiger) 同样的前奏,就不截图了 ,and 1=1和and 1=2进行测试,出现报错 还原sql语句 查看源代 ...