最近,我需要修改在continue中使用多个for each案例的人的代码。新增的是for each内部的一个新的控制循环,这很快就打破了continue逻辑。是否有一种好的方法可以在这样的循环中获得下一个列表项而不重写所有的连续情况?
// Additional control loops within the member function which cannot be
// turned into functions due to native C++ data types.
{
for each(KeyValuePair<String^,String^> kvp in ListOfItems) {
do { // new condition testing code
// a bunch of code that includes several chances to continue
} while (!reachedCondition)
}
}发布于 2018-04-08 16:46:07
continue和break进入内部最控制循环。我在for循环中使用了迭代器。因此,取决于您的ListOfItems是什么(即SortedList或Dictionary .)您可能可以迭代而不是continue。
int i=0;
Dictionary^ d = gcnew Dictionary<string, string>();
for (IEnumerator<KeyValuePair<string, string>>^ e = d->GetEnumerator();i< d->Count;i++) {
// do stuff
e->MoveNext();
}https://stackoverflow.com/questions/49659011
复制相似问题