Split - Index was outside the bounds of the array

后端 未结 7 553
野性不改
野性不改 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];
       }
    
    0 讨论(0)
提交回复
热议问题