From 250764b7ef6e0bd7924e07caa7576d87e7390350 Mon Sep 17 00:00:00 2001 From: Geir Okkenhaug Jerstad Date: Mon, 2 Dec 2024 12:45:04 +0100 Subject: [PATCH] Constructor --- .../StaticogIkkestatic/Places.cs | 14 ++++++++++---- .../StaticogIkkestatic/Program.cs | 12 ++++-------- 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/Emne 3/StaticogIkkestatic/StaticogIkkestatic/Places.cs b/Emne 3/StaticogIkkestatic/StaticogIkkestatic/Places.cs index 4c91dc6..d85cafc 100644 --- a/Emne 3/StaticogIkkestatic/StaticogIkkestatic/Places.cs +++ b/Emne 3/StaticogIkkestatic/StaticogIkkestatic/Places.cs @@ -2,10 +2,16 @@ namespace StaticogIkkestatic; public class Places { - public string PlaceName; - public string Municipality; - public string Region; - + public string PlaceName { get; private set; } + public string Municipality{ get; private set; } + public string Region{ get; private set; } + + public Places(string placeName, string municipality, string region) + { + PlaceName = placeName; + Municipality = municipality; + Region = region; + } public void ShowPlace() { var labelWidth = 8; diff --git a/Emne 3/StaticogIkkestatic/StaticogIkkestatic/Program.cs b/Emne 3/StaticogIkkestatic/StaticogIkkestatic/Program.cs index 07978ac..b898005 100644 --- a/Emne 3/StaticogIkkestatic/StaticogIkkestatic/Program.cs +++ b/Emne 3/StaticogIkkestatic/StaticogIkkestatic/Program.cs @@ -4,15 +4,11 @@ { static void Main(string[] args) { - var place = new Places(); - place.PlaceName = "Stavern"; - place.Municipality = "Larvik"; - place.Region = "Vestfold"; + var place = new Places( "Stavern","Larvik", "Vestfold"); + + var place2 = new Places("Rjukan","Tinn","Telemark"); + place.ShowPlace(); - var place2 = new Places(); - place2.PlaceName = "Rjukan"; - place2.Municipality = "Tinn"; - place2.Region = "Telemark"; place2.ShowPlace(); }