I have a problem with the following code:
public static void RestoreToolStripMenuItem(ToolStripMenuItem item, List<string>.Enumerator enumerator )
{
item.Text = enumerator.Current;
enumerator.MoveNext();
if (item.HasDropDownItems)
{
var itemsWithoutSeparators = item.DropDownItems.OfType<ToolStripMenuItem>();
foreach (var child in itemsWithoutSeparators)
{
RestoreToolStripMenuItem(child, enumerator);
}
}
}
After RestoreToolStripMenuItem is called recursively, the counter is reset (the current property points to the first element of the collection). It can be processed by clicking the enumerator link. I wonder why this is so? An enumerator is a structure. What caused this problem, the variability of the structure of the Enumerator?
source
share