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
Post a Comment