c# - Mutability of the Enumerator struct -
i have problem 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 called recursively, enumerator reseted (current property points first element of collection). can worked passing enumerator ref. wondering, why case? enumerator struct. caused problem, mutability of enumerator struct?
yes, it's changing state of structure causes that.
if pass structure value, using copy of in method, , 1 in calling code not change.
Comments
Post a Comment