title: strange behaviour of "as" operator
body: <p>So I have the following code:</p>
  
  <pre><code> /// &lt;summary&gt;
  /// The 'Prototype' abstract class
  /// &lt;/summary&gt;
  abstract class ColorPrototype
  {
      public abstract ColorPrototype Clone();
  }
  
  /// &lt;summary&gt;
  /// The 'ConcretePrototype' class
  /// &lt;/summary&gt;
  class Color : ColorPrototype
  {
      private int _red;
      private int _green;
      private int _blue;
  
      // Constructor
      public Color(int red, int green, int blue)
      {
          this._red = red;
          this._green = green;
          this._blue = blue;
      }
  
      // Create a shallow copy
      public override ColorPrototype Clone()
      {
          Console.WriteLine(
            "Cloning color RGB: {0,3},{1,3},{2,3}",
            _red, _green, _blue);
  
          return this.MemberwiseClone() as ColorPrototype;
      }
  }
  
  /// &lt;summary&gt;
  /// Prototype manager
  /// &lt;/summary&gt;
  class ColorManager
  {
      private Dictionary&lt;string, ColorPrototype&gt; _colors =
        new Dictionary&lt;string, ColorPrototype&gt;();
  
      // Indexer
      public ColorPrototype this[string key]
      {
          get { return _colors[key]; }
          set { _colors.Add(key, value); }
      }
  }
  </code></pre>
  
  <p>And in the main method I have:</p>
  
  <pre><code>ColorManager colormanager = new ColorManager();
  
  // Initialize with standard colors
  colormanager["red"] = new Color(255, 0, 0);
  
  // User clones selected colors
  ColorPrototype p1 = colormanager["red"].Clone();
  bool isColor = p1 is Prototype.Color;
  Color color1 = p1 as Color;
  </code></pre>
  
  <p>My question is why the variable p1 has type <code>Color</code> (<code>isColor</code> is true) if in the clone method I cast the result to <code>ColorPrototype</code> (<code>return this.MemberwiseClone() as ColorPrototype;</code>) ?</p>
  
  <p>Reference: <a href="http://www.dofactory.com/net/prototype-design-pattern" rel="nofollow">http://www.dofactory.com/net/prototype-design-pattern</a></p>