我有以下代碼:C#指數
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;
}
爲什麼錯誤發生...我只是傳遞參數,如果他們是數字我將它們添加到一個列表,如果沒有,我設置一個選項,繼續前進。這裏有什麼問題?
編輯:我通過2/t:Med 2 3 這些是論據。我已經檢查它arg [1](在這種情況下)是空的,但它不是
在此先感謝!
'arg'爲空或'ARG [J]字符串'沒有字符。你不能索引不存在的東西。 – 2012-08-06 13:35:47
如果沒有參數通過,該怎麼辦? – nothrow 2012-08-06 13:35:48
你有沒有在這裏放置一個斷點? ARG [j]的[0]。此時參數的值是多少 – 2012-08-06 13:35:52