CSharp · Console
using System;
public class Persoon
{
public string Achternaam { get; set; }
public string Voornaam { get; set; }
private DateTime _GeboorteDatum;
public DateTime Geboortedatum
{
get { return _GeboorteDatum; }
set
{
if (DateTime.Compare(value, DateTime.Today) != 1)
{
_GeboorteDatum = value;
}
else
{
throw new Exception("De geboortedatum mag niet in de toekomst liggen!");
}
}
}
public Persoon()
{
Achternaam = "";
Voornaam = "";
Geboortedatum = DateTime.Today;
}
public Persoon(string Achter, string Voor, DateTime Datum)
{
Achternaam = Achter;
Voornaam = Voor;
Geboortedatum = Datum;
}
public override string ToString()
{
return Voornaam + " " + Achternaam + " - " + Geboortedatum.ToShortDateString();
}
}
public class Program
{
public static void Main()
{
try{
Persoon Ik = new Persoon("Linthoudt","Geert", new DateTime(1969,10,1));
Console.WriteLine(Ik.ToString());
}
catch(Exception ex)
{
Console.WriteLine(ex.Message);
}
}
}