vb.net中应用 ArrayList 实例
|
源代码网整理以下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 源代码网整理以下 源代码网供稿. |
