title: How to check whether a base class object or derived object?
body: <p>I have a <code>BankAccount</code> class. <code>FixedBankAccount</code> and <code>SavingsBankAccount</code> are derived from it.<br>
  I need to throw an exception if the recieved object is not a derived object. I have the following code.</p>
  
  <pre><code>IEnumerable&lt;DBML_Project.BankAccount&gt; accounts = AccountRepository.GetAllAccountsForUser(userId);
  foreach (DBML_Project.BankAccount acc in accounts)
  {
      string typeResult = Convert.ToString(acc.GetType());
      string baseValue = Convert.ToString(typeof(DBML_Project.BankAccount));
  
      if (String.Equals(typeResult, baseValue))
      {
          throw new Exception("Not correct derived type");
      }
  }
  
  namespace DBML_Project
  {
  
  public  partial class BankAccount
  {
      // Define the domain behaviors
      public virtual void Freeze()
      {
          // Do nothing
      }
  }
  
  public class FixedBankAccount : BankAccount
  {
      public override void Freeze()
      {
          this.Status = "FrozenFA";
      }
  }
  
  public class SavingsBankAccount : BankAccount
  {
      public override void Freeze()
      {
          this.Status = "FrozenSB";
      }
  }
  
  } // namespace DBML_Project
  </code></pre>
  
  <p>Is there any better code than this?</p>