0

我试图发布无限数量的喜欢,但根据数组中存储的 cookie 数量循环 cookie 和代理。显然 i++ 是无法访问的代码。这是什么原因?

public void PostLikes()
{
   PostLike postLike = new PostLike();
   for (int i =0;i<this.cookies.ToArray().Length;i++)
   {
      for (int j = 0; ; j++)
      {
         postLike.PostLike(this.cookies[i], this.importedProxies[i], this.proxyUsernameTextbox, this.proxyPasswordTextbox, this.postsIds[j]);
      }
   }
}
4

3 回答 3

7

真正的问题是:

for (int j = 0; ; j++)

假设您没有任何其他控制语句(例如,,,,),break产生一个return无限循环gotothrow

你可能打算做这样的事情:

for (int j = 0; j < this.postsIds.Length; j++)
{
    ...
}
于 2013-11-07T20:21:28.067 回答
2

不要这样做

for (int i =0;i<this.cookies.ToArray().Length;i++)

因为

this.cookies.toArray().Length

它在 for 循环的每次迭代中进行评估,您每次都将 'this.cookies' 放入数组中,这样您就可以得到它的长度?:) 你正在增加方​​法的复杂性

于 2013-11-07T20:35:52.780 回答
1
for (int j = 0; ; j++)

这是一个死循环,因此无法到达 i++

于 2013-11-07T20:20:53.877 回答