Klassen2

CSharp · Console

/Program.cs

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 class Program
{
	public static void Main()
	{
		try{
			Persoon Ik = new Persoon();
			
			Ik.Achternaam = "Linthoudt";
			Ik.Voornaam = "Geert";
			Ik.Geboortedatum = new DateTime(2969,10,1);
				
			Console.WriteLine(Ik.Achternaam + ' ' + Ik.Voornaam + ' ' + Ik.Geboortedatum.ToShortDateString());
		}
		catch(Exception ex)
		{
			Console.WriteLine(ex.Message);
		}
	}
}
;