title: access objects in list c#
body: <p>The code is:</p>
  
  <pre><code>struct m1
  {
      public int a;
      public int b;
  }
  
  int main()
  {
      List &lt;m1&gt; mList;
      m1.initialize;
      //new. and add some items to it.
  </code></pre>
  
  <p>now I want to access the objects in mList
  at first I tried:</p>
  
  <pre><code>    for each(m1 it in mList)
      {
          m1.a = 5;
      }
  </code></pre>
  
  <p>but it failed. becuase after the for each I wrote m1.first().a on console. it was it's initialized value not 5.</p>
  
  <p>then I tried</p>
  
  <pre><code>    for (int counter = 0; counter &lt; mList.size(); counter++)
      {
          m1 it = mList[counter];
          it.a = 5;
      }
  </code></pre>
  
  <p>again the same problem.</p>
  
  <p>then I tried</p>
  
  <pre><code>    for (int counter = 0; counter &lt; mList.size(); counter++)
      {
          mList[counter].a = 5;
      }
  </code></pre>
  
  <p>it even didn't compiled. it gives me an error. it says something about not being modifiable return value of list.this[int].</p>
  
  <p>then I tried</p>
  
  <pre><code>    for (int counter = 0; counter &lt; mList.size(); counter++)
      {
          var m1 it = mList[counter];
          it.a = 5;
      }
  </code></pre>
  
  <p>it didn't work too.
  I tried all I could and everything that I found in internet and this site.
  Could you please help you to find a way to access parameters of objects(of type struct) in list?
  Obviously it is easy when list is made from objects(from classes). it comes to complication if I want to made a list from objects of structs.
  Any help would highly welcomed.</p>