Split - Index was outside the bounds of the array

后端 未结 7 592
野性不改
野性不改 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:09

    You can check the length of array before accessing its element by index.

    Change

       if(proxyAdrs[2] != null)
       {
                item.Username = proxyAdrs[2];
       }
    

    To

       if(proxyAdrs.Length > 2 )
       {
                item.Username = proxyAdrs[2];
       }
    

提交回复
热议问题