這是我第一次使用枚舉器接口。 我正試着看扔堆棧來查找下一個字符串的出現。 循環假設循環投擲我的標籤堆棧,並找出我的堆棧內的標籤是否是我正在尋找的標籤。一旦堆棧到達堆棧中的最後一個標記,它就會崩潰並在標題中發出錯誤。列表中的最後一個標籤也恰好是lookforthisTag字符串變量的第一個匹配項。我希望while語句在if語句找到匹配或所有堆棧項目進行比較時退出。C#錯誤附加信息:枚舉已完成
/*find next opening tag in stack */
int I = 1;
var enumerator = tags.GetEnumerator(); /// create a enumerator variable
/// move to the next tag in stack
while (enumerator.MoveNext() != false || found == true || I <= countofTags)
{
htmlTags currentTag = enumerator.Current; // this line causes error.
if (currentTag.open_tag == lookforthisTag)
{
found = true;
}
I++;
}///End while.
爲什麼不使用正常的foreach循環? – Steve