title: Update Struct in foreach loop in C#
body: <p>I have this code (C#): </p>
  
  <pre><code>using System.Collections.Generic;
  
  namespace ConsoleApplication1
  {
      public struct Thing
      {
          public string Name;
      }
  
      class Program
      {
          static void Main(string[] args)
          {
              List&lt;Thing&gt; things = new List&lt;Thing&gt;();
              foreach (Thing t in things) //  for each file
              {
                  t.Name = "xxx";
              }
          }
      }
  }
  </code></pre>
  
  <p>It won't compile.<br>
  The error is:   </p>
  
  <pre><code>Cannot modify members of 't' because it is a 'foreach iteration variable'
  </code></pre>
  
  <p>If I change <code>Thing</code> to a <code>class</code> rather than a <code>struct</code>, however, it does compile.  </p>
  
  <p>Please can someone explain what's going on? </p>