Quote:
Originally Posted by Korvacs
Code:
if (From != null)
{
byte Tries = (byte)Rnd.Next(0, From.Count);
ItemID = (uint)From[Tries - 1];
}
That should be fine now.
|
(Bear in mind this isn't directed at you Korvacs, I'd never baby a post like this if it was lol)
The return value on Random.Next returns:
>=min, <max
Meaning it should never *logically* produce a number that wouldn't suffice as an index. HOWEVER! There are exceptions to this rule, where is the max is 0, 0 will be returned. So what if the Length of the array is 0, we can't index 0; now can we? So therefore logically From[
0] would produce an exception where
From.Length is 0.
So the solution would be
Code:
if (From.Length > 0)
ItemID = (uint)From[Rnd.Next(From.Count)];
Get rid of the whole
if (From != null) scope. When would From ever equal
null when we initialize it just a couple lines before our if-statement and never set it back to null.