This is a well-known problem using a modified sentence in a call that a delegate creates. Adding a temporary variable should solve this problem:
foreach(Fruit f in _Fruits)
{
Fruit tmp = f;
field.Add(new Element(f.ToString(),delegate{fMethod(tmp);}));
}
This issue has been fixed in C # 5 ( see Eric Lippert's blog ).
source
share