脑子不转了,请大家帮助arrayList 删除的问题Dim arr As New ArrayListarr.Add(aaaa)arr.Add(bbb)arr.A
脑子不转了,请大家帮助arrayList 删除的问题 Dim arr As New ArrayList arr.Add("aaaa") arr.Add("bbb") arr.Add("ccc") Try Dim cou As Integer = arr.Count - 1 For k = 0 To cou Try Dim s As String = arr.Item(k) If s = "bbb" Then arr.Remove(s) ‘请问再加什么才是正确的??
End If Catch ex As Exception MsgBox(ex.Message) End Try Next
If s = "bbb" Then arr.Remove(s) Exit For End If [解决办法] For k = cou to 0 Step -1
................
[解决办法] 删除之后,arr.count已经变了,千万要注意这一点 [解决办法]
VB.NET code
Dim arr As New ArrayList Dim s As String = "ccc" arr.Add("aaa") arr.Add("bbb") arr.Add("ccc") For i As Integer = 0 To arr.Count - 1 If s = arr(i) Then arr.Remove(arr.Item(i)) Exit For End If Next For j As Integer = 0 To arr.Count - 1 Console.WriteLine(arr(j)) Next Console.ReadLine() [解决办法]