Split - Index was outside the bounds of the array

后端 未结 7 567
野性不改
野性不改 2020-12-18 04:25

Im using the following code to split up a string and store it:

string[] proxyAdrs = linesProxy[i].Split(\':\');
string proxyServer = proxyAdrs[0];
int proxyP         


        
7条回答
  •  死守一世寂寞
    2020-12-18 05:03

    It is that your i which might be lower than the 2 you are trying to set in as index :)

    if i >= 2 then you can do all of the follwing:----

    if(proxyAdrs[2] != null)
            {
                item.Username = proxyAdrs[2];
            }
    
            if (proxyAdrs[3] != null)
            {
                item.Password = proxyAdrs[3];
            }
    }
    else I suggest you get out :D
    

    But again, checking proxyAdrs.Lenght would be the best.

提交回复
热议问题