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

Popular posts from this blog

razor - Is this a bug in WebMatrix PageData? -

iphone - Requiring the presence of a method in an id -

xslt - Is it possible to select a node that just includes a subset of the child nodes? -