title: How to extend a Class in C#?
body: <p>I have my own Object, and I'd like to extend it, saving data from a person and adding new info.</p>
  
  <p>So the code would be:</p>
  
  <pre><code>public class Student : Person
  {
      public string code { get; set; }
  }
  </code></pre>
  
  <p>but when I try to init it and add the new value:</p>
  
  <pre><code>Person person = new Person("Paul", "Catch");
  Student student = (Person)person;
  student.code = "1234";
  </code></pre>
  
  <p>I got <code>System.InvalidCastException: Unable to cast object of type 'MyLayer.Person' to type 'Student'.</code></p>
  
  <p>Am I missing some point?</p>
  
  <p><strong>EDIT</strong>: maybe I wrong putting that Person class. You must suppose it become from a DB as object, such as <code>Person person = new MyPersons().First();</code></p>
  
  <p>So I won't to populate the new one with properties one by one, just extend one property thanks to the new object that extend the old one.</p>