c# - Index is out of range -


i getting error @ getproxy(), error index outofbounds.

error:

an unhandled exception of type 'system.argumentoutofrangeexception' occurred in mscorlib.dll additional information: index out of range. must non-negative , less size of collection. 

code:

static list<string> proxies = new list<string>();   private static string getproxy() {     lock (proxies)     {         return proxies[new random().next(0, proxies.count)];     } } 

it not empty, has proxy inside, error not in loading function, here.

i have added breakpoint , debugged it, proxies has value of count = 3 , proxies.count has value of 3.

the answer @gendolkari:

if proxies contains no elements @ all, trying access first element of empty list , throw exception.

return proxies[new random().next(0, proxies.count)]; 

==>

return proxies[new random().next(0, 0)]; 

==>

return proxies[0]; 

this causes argumentoutofrangeexception stated in documentation list(t).item because proxies empty.


Comments

Popular posts from this blog

sequelize.js - Sequelize group by with association includes id -

android - Robolectric "INTERNET permission is required" -

java - Android raising EPERM (Operation not permitted) when attempting to send UDP packet after network connection -