当前位置: 首页 > 图文教程 > 网络编程 > ASP.NET > vb.net中应用 ArrayList 实例

ASP.NET
.net开发实例:绑定到ADO.NET数据源
vb.net中应用 ArrayList 实例
用.net 处理xmlHttp发送异步请求
编写ASP.NET应用程序的十大技巧
完全不使用配置文件构建和使用WCF服务
VB.net2008精彩实例,窗体应用技巧
VB.Net实现Web Service的基础
实用技巧:.Net框架类库中定时器类的使用
ASP.NET MVC:实现我们自己的视图引擎
基于ASP.NET MVC框架开发Web论坛应用程序
用VB.net2008打造你的影音播放器
如何使用.NET实现断点续传功能
如何用.NET技术在线生成网站LOGO
挖掘ADO.NET Entity框架的性能
编写ASP.NET应用程序的十大技巧 (1)
Asp.NET大文件上传开发总结集合
.net开发:如何为程式码加上行号
ASP.NET 中整合JavaScript技巧
浅谈.NET中加密和解密的实现方法
浅析ASP.NET 2.0 Client Callback

ASP.NET 中的 vb.net中应用 ArrayList 实例


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-09-23   浏览: 68 ::
收藏到网摘: n/a

ArrayList 就是数组列表,它位于 System.Collections名称空间下。是集和类型。 与 ArrayList 同胞的还有一个List,他们的实用很相似。我们只介绍一些关于ArrayList的一些东东。

  ArrayList有三个构造器:

  ArrayList()

  ArrayList(int32)

  ArrayList(ICollection)

  一个简单的例子如下:

  Dim t As New ArrayList()

  t.Add("Northsnow")

  Dim d As New Collection

  d.Add("塞北的雪")

  d.Add("http://blog.csdn.net/precipitant")

  t.AddRange(d)

  For Each aa As String In t

  MsgBox(aa.ToString())

  Next

  '会依次输出:

  'Northsnow

  '塞北的雪

  'http://blog.csdn.net/precipitant

  ArrayList的构造器可以接受一个集和,例子如下:

  Dim d As New Collection

  d.add("Northsnow")

  d.Add("塞北的雪")

  d.Add("http://blog.csdn.net/precipitant")

  Dim t As New ArrayList(d)

  Dim sb As New System.Text.StringBuilder()

  If t.Count >0 Then

  sb.Append("ArrayList中共有 成员 ")

  sb.Append(t.Count.ToString)

  sb.Append(" 个")

  For Each aa As String In t

  sb.AppendLine()

  sb.Append(aa)

  Next

  End If

  MsgBox(sb.ToString)

  '最后输出结果为:

  'ArrayList中共有 成员 3 个

  'Northsnow

  '塞北的雪

ArrayList 就是数组列表,它位于 System.Collections名称空间下。是集和类型。 与 ArrayList 同胞的还有一个List,他们的实用很相似。我们只介绍一些关于ArrayList的一些东东。

  ArrayList有三个构造器:

  ArrayList()

  ArrayList(int32)

  ArrayList(ICollection)

  一个简单的例子如下:

  Dim t As New ArrayList()

  t.Add("Northsnow")

  Dim d As New Collection

  d.Add("塞北的雪")

  d.Add("http://blog.csdn.net/precipitant")

  t.AddRange(d)

  For Each aa As String In t

  MsgBox(aa.ToString())

  Next

  '会依次输出:

  'Northsnow

  '塞北的雪

  'http://blog.csdn.net/precipitant

  ArrayList的构造器可以接受一个集和,例子如下:

  Dim d As New Collection

  d.add("Northsnow")

  d.Add("塞北的雪")

  d.Add("http://blog.csdn.net/precipitant")

  Dim t As New ArrayList(d)

  Dim sb As New System.Text.StringBuilder()

  If t.Count >0 Then

  sb.Append("ArrayList中共有 成员 ")

  sb.Append(t.Count.ToString)

  sb.Append(" 个")

  For Each aa As String In t

  sb.AppendLine()

  sb.Append(aa)

  Next

  End If

  MsgBox(sb.ToString)

  '最后输出结果为:

  'ArrayList中共有 成员 3 个

  'Northsnow

  '塞北的雪

  'http://blog.csdn.net/precipitant

另外还可以给 ArrayList的构造器传递一个整数,以设定ArrayList的初始容量。并可以通过 更改 Capacity属性的值更改 当前 ArrayList的容量,也可以用   TrimToSize方法将容量压缩成实际的元素数量,例子如下:

  Dim t As New ArrayList(10)

  Dim d As New Collection

  d.Add("Northsnow")

  d.Add("塞北的雪")

  d.Add("http://blog.csdn.net/precipitant")

  t.AddRange(d)

  MsgBox(t.Capacity)

  t.Capacity = 6

  MsgBox(t.Capacity)

  t.TrimToSize()

  't.Capacity = t.Count 与 t.TrimToSize() 等效

  MsgBox(t.Capacity)

  '依次输出:

  '10

  '6

  '3

另外还可以给 ArrayList的构造器传递一个整数,以设定ArrayList的初始容量。并可以通过 更改 Capacity属性的值更改 当前 ArrayList的容量,也可以用   TrimToSize方法将容量压缩成实际的元素数量,例子如下:

  Dim t As New ArrayList(10)

  Dim d As New Collection

  d.Add("Northsnow")

  d.Add("塞北的雪")

  d.Add("http://blog.csdn.net/precipitant")

  t.AddRange(d)

  MsgBox(t.Capacity)

  t.Capacity = 6

  MsgBox(t.Capacity)

  t.TrimToSize()

  't.Capacity = t.Count 与 t.TrimToSize() 等效

  MsgBox(t.Capacity)

  '依次输出:

  '10

  '6

  '3

由于ArrayList是集和类型,所以它具有一些集和的操作方法。比如 遍历,查找,插入 等操作。同时 ArrayList还相当于一个大小可自由改变的一维数组。所以当然也可以像对待数组一样对他进行操作。