title: ReSharper Warning - Access to Modified Closure
body: <p>I have the following code:</p>
  
  <pre><code>string acctStatus = account.AccountStatus.ToString();
  if (!SettableStatuses().Any(status =&gt; status == acctStatus))
      acctStatus = ACCOUNTSTATUS.Pending.ToString();
  </code></pre>
  
  <p>Note that account.AccountStatus is an enum of type ACCOUNTSTATUS.  On the second line, ReSharper is giving me the warning "Access to Modified Closure" for acctStatus.  When I do the recommended operation, <em>Copy to local variable</em>, it modifies the code to the following:</p>
  
  <pre><code>string acctStatus = realAccount.AccountStatus.ToString();
  string s = acctStatus;
  if (!SettableStatuses().Any(status =&gt; status == s))
      acctStatus = ACCOUNTSTATUS.Pending.ToString();
  </code></pre>
  
  <p>Why is this better or preferable to what I had originally?</p>
  
  <p><strong>EDIT</strong></p>
  
  <p>It also recommends <em>Wrap local variable in array</em>, which produces:</p>
  
  <pre><code>string[] acctStatus = {realAccount.AccountStatus.ToString()};
  if (!SettableStatuses().Any(status =&gt; status == acctStatus[0]))
      acctStatus[0] = ACCOUNTSTATUS.Pending.ToString();
  </code></pre>
  
  <p>This seems downright wacky to me.</p>