我試圖檢索隔離的存儲文件中的所有數據。 但我得到一個索引超出範圍的錯誤。 家^ ^如何唷指數超出範圍wp7
StreamReader readFile = new StreamReader(new IsolatedStorageFileStream("AlarmFolder\\alarm.txt", FileMode.Open, myStore));
string[] alarmDetailsSeparated;
String fileText = readFile.ReadLine();
//alarmDetailsSeparated is the array that hold the retrieved alarm details from alarm.txt and is split by '^'
alarmDetailsSeparated = fileText.Split(new char[] { '^' });
foreach (string home in alarmDetailsSeparated)
{
for (i = 0; i < alarmDetailsSeparated.Length;)
{
if (test > 0)
{
i = test;
}
dateSeparate = alarmDetailsSeparated[i];
timeSeparate = alarmDetailsSeparated[i + 1];
labelSeparate = alarmDetailsSeparated[i + 2];
date = dateSeparate;
time = timeSeparate;
label = labelSeparate;
test = test + 3 ;
break;
}
MessageBox.Show("i is " + alarmDetailsSeparated[i]);
MessageBox.Show("i + 1 is " + alarmDetailsSeparated[i + 1]);
MessageBox.Show("i + 2 is " + alarmDetailsSeparated[i + 2]);
}
如果你知道有多少元素應該是在'alarmDetailsSeparated',爲什麼不對其進行索引,而不是直接通過他們的循環? 當然,您應該確認實際存在的元素的預期數量。 –
你的for循環看起來很奇怪,目前還不清楚'test'是在哪裏聲明的,它包含了什麼。 – Filburt
你能舉個例子嗎?我不是很確定如何做 –