serialization/person-1/person.cs - The Person class - Serializable. | Lecture 10 - slide 32 : 40 Program 1 |
using System; [Serializable] public class Person{ private string name; private int age; // Redundant private Date dateOfBirth, dateOfDeath; public Person (string name, Date dateOfBirth){ this.name = name; this.dateOfBirth = dateOfBirth; this.dateOfDeath = null; age = Date.Today.YearDiff(dateOfBirth); } public Date DateOfBirth { get {return new Date(dateOfBirth);} } public int Age{ get {return Alive ? age : dateOfDeath.YearDiff(dateOfBirth);} } public bool Alive{ get {return dateOfDeath == null;} } public void Died(Date d){ dateOfDeath = d; } public void Update(){ age = Date.Today.YearDiff(dateOfBirth); } public override string ToString(){ return "Person: " + name + " *" + dateOfBirth + (Alive ? "" : " +" + dateOfDeath) + " Age: " + age; } }