text.vbPublic IDs = New ArrayList()
Public Sub Add(ByVal id As Integer)
If Not IsInFavoritesList(id) Then
If IDs.Count < 3 Then
IDs.Add(id)
Else
Dim i As Integer
For i = 0 To IDs.Count - 2
MsgBox(IDs(i).ToString)
Dim temp As Integer = IDs(0)
IDs(i) = IDs(i + 1)
If i + 1 = 2 Then
IDs(i + 1) = IDs.Add(id)
Exit For
End If
Next
End If
End If
End Sub说明:我想要完成的功能是控制IDs的个数(如3个),如果超过了这个数,就用先进先出的方法,使个数始终是3个!
Public Sub Add(ByVal id As Integer)
If Not IsInFavoritesList(id) Then
If IDs.Count < 3 Then
IDs.Add(id)
Else
Dim i As Integer
For i = 0 To IDs.Count - 2
MsgBox(IDs(i).ToString)
Dim temp As Integer = IDs(0)
IDs(i) = IDs(i + 1)
If i + 1 = 2 Then
IDs(i + 1) = IDs.Add(id)
Exit For
End If
Next
End If
End If
End Sub说明:我想要完成的功能是控制IDs的个数(如3个),如果超过了这个数,就用先进先出的方法,使个数始终是3个!
IDs(i + 1) = IDs.Add(id)
Exit For
End If
应该改为IDs(i + 1) = IDs(IDs.Count - 1)
IDs里面的内容是这样的:添加前3个是没问题:productid=31 or productid=32 or productid=33;
到第四个的时候,就是这样的了:productid=32 or productid=33 or productid=3 or productid=34;请问为什么会这样?
改成IDs(i + 1) = id不就行了!
IDs里面的内容是这样的:添加前3个是没问题:productid=31 or productid=32 or productid=33;
到第四个的时候,就是这样的了:productid=32 or productid=33 or productid=3 or productid=34;注:productid=3 里的这个3实际上是ids的序号,ids(i)=ids(i+1) 实际上是它的序号滚动了加一个中转数组:第一步:先将ids里的值逐一取出并赋给数组
第二步:通过数组实现arr(i)=arr(i+1)
第三步:再用数组对ids进行覆盖(第一步反方向)