将 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; // DropDownList DropDownList1; DropDownList1.DataBind(); 结果为 e d c b a 六.查找 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"); int nIndex = 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"); int nIndex = aList.LastIndexOf("a"); //值为2而不是0 g) public virtual bool Contains(object item); 确定某个元素是否在 ArrayList 中。包含返回true,否则返回false 七.其他 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 中元素的实际数量。 如果不向列表中添加新元素,则此方法可 上一页 [1] [2] [3] [4] 下一页 [Web开发]一个关于ASP运行时间计算的代码 [Web开发]ASP:检测含有中文字符串的实际长度 [Web开发]asp 中英文字符长度检测判断函数 [Web开发]安全维护 IIS asp 站点的高级技巧 [C语言系列]NET 中C#的switch语句的语法 [Access]ASP&SQL让select查询结果随机排序的实现方法 [Web开发]ASP字符串截取函数 [Web开发][asp]关键词只替换一次的写法 [Web开发]Asp无组件生成缩略图方法详解 [Web开发]asp编程中优化数据库方法详解
|