vb.net中应用 ArrayList
来源:互联网 发布:linux mint 主题 编辑:程序博客网 时间:2024/05/16 06:14
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
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
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
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还相当于一个大小可自由改变的一维数组。所以当然也可以像对待数组一样对他进行操作。
- vb.net中应用 ArrayList
- VB.Net中应用ArrayList实例
- VB.Net--应用ArrayList实例
- VB.NET中应用 StringWriter
- vb.net Arraylist去重
- 在VB.NET中应用SQLDMO
- 在VB.NET中应用Agent技术
- 在VB.NET中应用SQLDMO
- 在VB.NET中应用SQLDMO
- 在VB.NET中应用SQLDMO
- VB.net中HOOK的应用(转)
- VB.net中HOOK的应用
- 在VB.NET中应用SQLDMO
- 在VB.NET中应用SQLDMO
- VB.net中HOOK的应用
- 在VB.NET中应用SQLDMO
- vb.net中自定义属性的应用
- 在vb.net中应用OO4O
- DHTML+JAVAScript学习资源
- 在.NET程序中小心使用String类型
- .net 接口示例
- 正则表达式验证日期和Email
- 小故事
- vb.net中应用 ArrayList
- 杀人游戏攻略
- 李开复谈工作:不要成为“紧急”的奴隶
- MDX函数参考
- gloox今天发布新版本0.86了
- MS面试题
- Java中ThreadLocal的设计与使用
- 不知名的树
- 微软产品居然出现中文兼容问题