title: How to clone an inherited object?
body: <p>I've got a <code>Tile</code> class with this method:</p>
  
  <pre><code>    public object Clone()
      {
          return MemberwiseClone();
      }
  </code></pre>
  
  <p>And another class <code>Checker</code> that inherits from <code>Tile</code>.</p>
  
  <p>I also have a <code>Board</code> class that is a <code>List&lt;Tile&gt;</code>. I want to clone the board, so I wrote this:</p>
  
  <pre><code>    public Board Clone()
      {
          var b = new Board(width, height);
          foreach (var t in this) b.Add(t.Clone());
          return b;
      }
  </code></pre>
  
  <p>But it throws an error:</p>
  
  <blockquote>
    <p>cannot convert from 'object' to 'Checkers.Tile'</p>
  </blockquote>
  
  <p>Now I can make the <code>Tile.Clone</code> method return a <code>Tile</code> instead, but then will the <code>MemberwiseClone</code> copy the additional properties in the sub-<code>Checker</code> as well?</p>
  
  <hr>
  
  <p>If that's not the problem, what's the semantic difference between the above <code>Board.Clone</code> method and this?</p>
  
  <pre><code>    public Board Clone()
      {
          using (var ms = new MemoryStream())
          {
              var bf = new BinaryFormatter();
              bf.Serialize(ms, this);
              ms.Position = 0;
              return (Board)bf.Deserialize(ms);
          }
      }
  </code></pre>
  
  <p>Because they're definitely having different effects on my program, even though when I print the board it <em>looks</em> the same. I don't think something is being <em>cloned</em> but a reference is being returned. The <code>Board</code> ctor looks like this:</p>
  
  <pre><code>    public Board(int width = 8, int height = 8)
      {
          this.width = width;
          this.height = height;
          this.rowWidth = width / 2;
          this.Capacity = rowWidth * height;
      }
  </code></pre>
  
  <hr>
  
  <p>The <code>Tile</code> class actually doesn't have any properties. The checker just has two enums properties:</p>
  
  <pre><code>public enum Color { Black, White };
  public enum Class { Man, King };
  
  public class Checker : Tile
  {
      public Color Color { get; set; }
      public Class Class { get; set; }
  </code></pre>