title: C# explicit cast superclass to derived class and get specific variables
body: <p>I have an abstract class, Tile.
  I have another class, WebTile, inheriting the Tile-class.
  The WebTile have a <code>private string html</code>, that Tile does not have.</p>
  
  <pre><code> public abstract class Tile
  {
      private string name;
      private string description;
  
      public string Name
      {
          get { return name; }
      }
  
      public string Description
      {
          get { return description; }
      }
  
      protected Tile(string name, string description)
      {
          this.name = name;
          this.description = description;
      }
  }
  
   public class WebTile : Tile
      {
          private string html;
          public string HTML
          {
              get { return html; }
          }
          public WebTile(string name, string description, string html) : base(name, description)
          {
              this.html = HTML;
          }
      }
  </code></pre>
  
  <p>I have a method that returns a list of Tiles <code>(List&lt;Tile&gt;)</code></p>
  
  <p>I loop through the list, and cast the Tiles of type WebTile to a WebTile.</p>
  
  <p>And then i want to get the html-string. But it has become empty after the cast?! What am i missing?</p>
  
  <pre><code>foreach (Tile tile in xmlparser.GetTiles())
              {
                  switch (tile.GetType().ToString())
                  {
                      case "Dashboard.Tiles.WebTile":
                          WebTile _tile = tile as WebTile;
                          sb.Append("&lt;div class=\"panel panel-default\"&gt;");
                          sb.Append("&lt;div class=\"panel-heading\"&gt;" + _tile.Name + "&lt;/div&gt;");
                          sb.Append("&lt;div class=\"panel-body\"&gt;");
                          sb.Append(_tile.HTML); // &lt;--- THIS IS EMPTY!!
                          sb.Append("&lt;/div&gt;").Append("&lt;/div&gt;");
                          break;
                      default:
                          break;
                  }
               }
  </code></pre>