title: Linq and cloning Objects in C#
body: <p>This question is not about cloning objects but about the correct use of Linq to use an extension method to clone a list of objects.Code if just for illustration.</p>
  
  <pre><code>using System;
  using System.Collections.Generic;
  using System.Linq;
  using System.Text;
  using System.Threading.Tasks;
  
  namespace ConsoleApplication1
  {
      class Program
     {
          static void Main(string[] args)
          {
             List&lt;MyObj&gt; myObjs = DB.GetAllMyObjs(); //fictitious database calls returns a list of Objs
  
  
          //I now want to use my extension method clone to clone all the MyObjs in myObjs
          // this throws an error;
          List&lt;MyObj&gt; myObj2 = myObjs.ForEach(a =&gt; a.Clone()).ToList(); //ERROR = "."cannot be applied to type void
  
  
      }
  }
  
  public class MyObj 
  {
      public int Id { get; set; }
  
  
  
  }
  public static class MyObjExtentions
  {
      public static MyObj  Clone(this MyObj myObj)
      {
          var myObjClone = new MyObj();
          myObjClone.Id = myObj.Id;
          return myObjClone;
      }
  }
  </code></pre>
  
  <p>}</p>
  
  <p>I am getting an error on the Linq code. is it possible to do this or do you need a foreach loop.</p>