title: C# Set field of all items in list to same value
body: <p>So when you get back an list, one value is filled by the repository but the other you want to have the same value for each item in the list. It feels like an for each loop is the a lot of code for simple functionality. Is there a way to shorten the code.</p>
  
  <p>So some context. This is an example class.</p>
  
  <pre><code>public class ExampleClass
  {
      public string A { get; set; }
      public string B { get; set;
  }
  </code></pre>
  
  <p>This is an method that works:</p>
  
  <pre><code>public IEnumerable&lt;ExampleClass&gt; GetAll(string bValue)
  {
      var exampleList = repo.GetAll(); //Asume that the repo gives back the an list with A filled;
      var returnValue = new List&lt;ExampleClass&gt;();
      foreach (var item in exampleList)
      {
          item.B= bValue;
          returnValue.Add(item);
      }
      return returnValue;
  }
  </code></pre>
  
  <p>It would be great if there could something like:</p>
  
  <pre><code>public IEnumerable&lt;ExampleClass&gt; GetAll(string bValue)
  {
      return repo.GetAll().Map(i =&gt; i.B = bValue);
  }
  </code></pre>
  
  <p>Does anyone knows something like this.</p>