5 Replies Last post: Feb 7, 2011 4:22 AM by Naiem Yeganeh  
Guest
Currently Being Moderated

Feb 19, 2008 12:15 PM

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

 

 

Francois Chartrand Newbie 1 posts since
Oct 5, 2010
Currently Being Moderated
Oct 7, 2010 6:19 AM in response to: Oren Novotny
Re: What does "Access to modified closure" mean?

Is it still a valid warning if using value types (i.e. struct)?

Andrey Serebryansky JetBrains 2,900 posts since
Jan 12, 2005
Currently Being Moderated
Oct 7, 2010 1:05 PM in response to: Francois Chartrand
Re: What does "Access to modified closure" mean?

Hello Francois,

 

Yes, this is still a valid warning for value types. Thank you!

 

Andrey Serebryansky

Senior Support Engineer

JetBrains, Inc

http://www.jetbrains.com

"Develop with pleasure!"

 

Is it still a valid warning if using value types (i.e. struct)?

 

---

Original message URL:

http://devnet.jetbrains.net/message/5274174#5274174

 

 

 

Naiem Yeganeh Newbie 1 posts since
Feb 7, 2011
Currently Being Moderated
Feb 7, 2011 4:22 AM in response to: Gabriel Lozano-Moran
Re: What does "Access to modified closure" mean?

http://qualityofdata.com/2010/12/27/resharper-access-to-the-modified-closure-simplified/

 

Check the post from the above link. It describes it with examples.

More Like This

  • Retrieving data ...