title: Inheritance & BASE Classes in ASP.NET MVC
body: <p>I’m trying to understand inheritance within an MVC application and I have a couple of things I would like clear up if someone can please help.</p>
  
  <p><strong>Question 1</strong></p>
  
  <p>If I have the following three classes which inherit off each other as follows</p>
  
  <pre><code>Public class StandardPage
  
  Public class ArticlePage : StandardPage
  
  Public class NewsPage : ArticlePage
  </code></pre>
  
  <p>Is the StandardPage class the only BASE class here or is the ArticlePage class also referred to as a BASE class because the NewsPage class derives from it? </p>
  
  <p>In a nut shell are classes that derive from other classes also referred to as BASE classes (for the class that inherits it)?</p>
  
  <p><strong>Question 2</strong></p>
  
  <p>If I have the above classes defined when working in the strongly typed view file (with Razor), if I write the following code</p>
  
  <pre><code>@foreach (var article in Model.Articles)
  {
  if (article is StandardPage)
          {
  var articlePage = article as StandardPage;
  </code></pre>
  
  <p>If the object inside the article var is of type StandardPage, ArticlePage or news page then the articlePage var will be populated without any issues because StandardPage is the BASE class which ArticlePage &amp; NewsPage both inherit from, however if I change the code to the following </p>
  
  <pre><code>@foreach (var article in Model.Articles)
  {
  if (article is StandardPage)
          {
  var articlePage = article as ArticlePage;
  </code></pre>
  
  <p>When the object inside the article var is of type StandardPage I will receive an ‘Object reference not set to an instance of an object’ when trying to populate the articlePage var because StandardPage does not inherit from an ArticlePage (it’s the other way around) and therefore I can’t cast something of type StandardPage into and ArticlePage.</p>
  
  <p>Fingers crossed im nearly there with understanding this but if im way off the mark could someone please point me in the right direction</p>
  
  <p>Thanks in advance</p>