每个循环加倍

时间:2013-09-01 06:57:24

标签: vb.net

这个循环有什么问题?

我注意到a字符串没有改变,但我想它应该移动到列表中的下一个字符串,而它适用于ProxyList

Public Class Form1

    Public ProxyList As New List(Of String)
    Public AccountList As New List(Of String)

    For Each a As String In AccountList
        Dim z() As String = a.Split(":")

        For Each p As String In ProxyList
           ' SENDS WEBREQUESTS BY USING ACCOUNTS AND SETS PROXY '
        Next
    Next

结束班

1 个答案:

答案 0 :(得分:0)

对于proxyList中的每个项目,这将循环一次帐户列表,如果帐户列表中有5个项目,而在proxyList中有10个项目,那么此代码将循环50次。这段代码没有任何问题,只是它与你想要的不符。

根据你的评论,你希望accountList和proxyList都向前推进,你应该真正定义一个新类:

Public Class ProxyAccount
    Public Proxy As String
    Public Account As String
End Class

然后您的代码变为:

Public Class Form1

    Public ProxyList As New List(Of ProxyAccount)

    For Each pa As ProxyAccount In ProxyList 
        Dim a as String = pa.Account
        Dim z() As String = a.Split(":") 
        Dim p as String = pa.Proxy   
        ' SENDS WEBREQUESTS BY USING ACCOUNTS AND SETS PROXY '
        Next
    Next
End Class

或者你也可以这样做:

Public Class Form1

    Public ProxyList As New List(Of String)
    Public AccountList As New List(Of String)

    For i as Integer = 0 To ProxyList.Count - 1  
        If i >= AccountList.Count Then   
            Exit For
        End If
        Dim a As String = AccountList(i)    
        Dim z() As String = a.Split(":")  
        Dim p as String = ProxyList(i)  
        ' SENDS WEBREQUESTS BY USING ACCOUNTS AND SETS PROXY '
    Next
End Class

这两个中的任何一个都可以正常工作,但您需要重构代码以使其更清晰。