title: Why items of an IEnumerable variable cannot be updated when it is pointing to an IEnumerable but works when pointing to an implemented collection
body: <p>I have already read answers in questions <a href="https://stackoverflow.com/questions/7304372/update-object-in-ienumerable-not-updating">Update object in IEnumerable&lt;&gt; not updating?</a> and <a href="https://stackoverflow.com/questions/9104181/updating-an-item-property-within-ienumerable-but-the-property-doesnt-stay-set">Updating an item property within IEnumerable but the property doesn&#39;t stay set?</a> but I would like to <strong>Understand why</strong> it is not working when I try to update an item in an IEnumerable.</p>
  
  <p>What I don't understand is:</p>
  
  <p>I cannot update an item of an Ienumerable using .ElementAt() method when the source collection is pointing to an Ienumerable.</p>
  
  <p>However the same code works when the source Ienumerable is pointing to a list.</p>
  
  <p><strong>1</strong> Could someone be kind to explain what happens behind the scenes? </p>
  
  <p><strong>2</strong> Why C# compiler doesn't (or can't) error on this?</p>
  
  <p><strong>3</strong> Also doesn't this invalidate using Ienumerable to define types when we have to convert Ienumerables to Lists whenever it needs updating?</p>
  
  <p>I am sure I am missing something here I'd appriciate if someone can explain what's going on behind the scenes.</p>
  
  <p>This is my code:</p>
  
  <p>1 - Collection doesn't get updated:</p>
  
  <pre><code>class Person
  {
      public string Name { get; set; }
  }
  
  class Program
  {
      static void Main(string[] args)
      {
          var numbers = new int[] {1,2,3};
  
          var people = numbers.Select(n =&gt; new Person { Name = "Person " + n.ToString() });
  
  
          for (int i = 0; i &lt; people.Count(); i++)
          {
              people.ElementAt(i).Name = "New Name";
          }
  
          people.ToList().ForEach(i =&gt; Console.WriteLine(i.Name));
  
          // OUTPUT: Person1, Person2, Person3
      }
  
  }
  </code></pre>
  
  <p>2 - Collection gets updated when I add .ToList() to the collection creation line (Note 3rd line in the Main method)</p>
  
  <pre><code>class Person
  {
      public string Name { get; set; }
  }
  
  class Program
  {
      static void Main(string[] args)
      {
          var numbers = new int[] {1,2,3};
  
          // Note the .ToList() at the end of this line.
          var people = numbers.Select(n =&gt; new Person { Name = "Person " + n.ToString() }).ToList();
  
  
          for (int i = 0; i &lt; people.Count(); i++)
          {
              people.ElementAt(i).Name = "New Name";
          }
  
          people.ToList().ForEach(i =&gt; Console.WriteLine(i.Name));
  
  
          Console.ReadLine();
          // OUTPUT: New Name, New Name, New Name
      }
  
  }
  </code></pre>