I have the following code :
public List<IAction> Dispatch(string[] arg)
{
int time=0;
int i = 0;
int j = 0;
List<IAction> t = new List<IAction>(10);
do
{
if (arg[j][0] == '/') // I get index out of bounds here
{
Options opt = new Options();
time = opt.Option(arg[j]);
j++;
}
else
{
if (int.Parse(arg[j]) >= 0 && int.Parse(arg[j]) <= 20)
{
t.Add(new ComputeParam(int.Parse(arg[j])));
i++;
j++;
}
}
} while (i != arg.Length);
for (int z = 0; z < t.Count; z++)
{
((ComputeParam)t[z]).Time = time;
}
return t;
}
Why does the error happen… I just pass the arguments and if they are numbers I add them to a list, if not I set an option and move on. What is the problem here?
Edit : I pass 2 /t:Med 2 3
those are the arguments. I aleready checked it arg[1] (in this case) is null, but it’s not.
I see a couple of possible issues here:
arg[]is empty, you will get the exceptionarg[j]is an empty string, you will get the exceptionjis being incremented, butiis not.I think this will fix it: