title: How do I clone a Collection<T>?
body: <p>I have an enumeration, <code>Fruit</code>, and a class, <code>FruitCollection</code>, which derives <code>Collection&lt;Fruit&gt;</code>.  I couldn't find a way to clone <code>FruitCollection</code> using .NET and I found <a href="http://social.msdn.microsoft.com/Forums/en-US/1e279146-7a5b-43ab-ba44-28f19a5a10b8/create-deep-copy-of-collectiont?forum=csharpgeneral" rel="noreferrer">this MSDN article</a> which defined a <code>DeepClone()</code> function and used <code>MemberwiseClone()</code>.  Now, since this is an enumeration, I don't think I need to "deep" clone it, so I thought <code>MemberwiseClone()</code> would be sufficient.  However, when I try it in PowerShell, the cloned object seems to simply be a pointer to the original object and not a clone.  What am I doing wrong?</p>
  
  <p>Is there another way to simply clone a <code>Collection</code>?  <code>FruitCollection</code> has no other custom members.</p>
  
  <p>C# code:</p>
  
  <pre><code>public enum Fruit
  {
      Apple = 1,
      Orange = 2
  }
  
  public class FruitCollection : Collection&lt;Fruit&gt;
  {
      public FruitCollection Clone()
      {
          return Clone(this);
      }
  
      public static FruitCollection Clone(FruitCollection fruitCollection)
      {
          return (FruitCollection)fruitCollection.MemberwiseClone();
      }
  
  }
  </code></pre>
  
  <p>PowerShell Output:</p>
  
  <pre><code>PS&gt; $basket1 = New-Object TestLibrary.FruitCollection
  PS&gt; $basket1.Add([TestLibrary.Fruit]::Apple)
  PS&gt; $basket2 = $basket1.Clone()
  PS&gt; $basket1.Add([TestLibrary.Fruit]::Orange)
  PS&gt; $basket2
  Apple
  Orange
  </code></pre>