0

What does "Access to modified closure" mean?

Hello

I have the following code:

01 foreach(TimeZoneInfo info in TimeZoneInfo.GetSystemTimeZones())
02 {
03 if(list.Count(t => t.Name == info.Id) == 0)
04 {
05 result = false;
06 }
07 }

In line 03 I see that info is underlined and the message is "Access to
modified closure" and I get the refactoring option to copy it to a local
variable resulting in this:

01 foreach(TimeZoneInfo info in TimeZoneInfo.GetSystemTimeZones())
02 {
03 TimeZoneInfo info1 = info;
04 if(list.Count(t => t.Name == info1.Id) == 0)
05 {
06 result = false;
07 }
08 }

What exactly is meant with "Access to modified closure"?

Gabriel Lozano-Moran

5 comments

Please sign in to leave a comment.