title: deep clone a List of object in c#
body: <p>I have a C# class called "SmallClass".</p>
  
  <p>I have an existing list myList containing objects of type "SmallClass"</p>
  
  <p>I want a deep clone of the list "myList". That is, deep Clone the containing list and deep clone the objects contained in the list. </p>
  
  <p>How should I do this.</p>
  
  <pre><code>    public class SmallClass: ICloneable {
  
      public string str1;
      public string str2;
      public string str3;
  
       public SmallClass Clone() //This just deep clones 1 object of type "SmallClass"
              {
                  MemoryStream m = new MemoryStream();
                  BinaryFormatter b = new BinaryFormatter();
                  b.Serialize(m, this);
                  m.Position = 0;
                  return (SRO)b.Deserialize(m);
              }
  
        public override equals(Object a)
          {
                  return Object.Equals(this.str1 &amp;&amp; a.str1);
              }
      }
  
      public class AnotherClass
      {
             SomeCode();
             List&lt;SmallClass&gt; myList = new List&lt;SmallList&gt;();  //myList is initialized.
  
  
             // NOW I want to deep clone myList. deep Clone the containing list and deep clone the objects contained in the list.
  
           List&lt;SmallClass&gt; newList = new List&lt;SmallClass&gt;();
        foreach(var item in myList)
          {
             newList.Add((SmallClass)item.Clone());
          }       
  </code></pre>
  
  <p>}</p>