refactoring

This commit is contained in:
Geir Okkenhaug Jerstad 2024-12-02 12:39:21 +01:00
parent 0950feff85
commit 96c1b52110
2 changed files with 41 additions and 12 deletions

View file

@ -0,0 +1,30 @@
namespace StaticogIkkestatic;
public class Places
{
public string PlaceName;
public string Municipality;
public string Region;
public void ShowPlace()
{
var labelWidth = 8;
ShowSeperatorRow();
ShowFielAndValue("Navn", labelWidth,PlaceName);
ShowFielAndValue("Kommune", labelWidth,Municipality);
ShowFielAndValue("Fylke", labelWidth,Region);
ShowSeperatorRow();
}
static void ShowFielAndValue(string label, int labelWidth,string fieldValue)
{
labelWidth = label.Length;
Console.WriteLine(" " + label +":" + String.Empty.PadLeft(labelWidth, ' ') + fieldValue);
}
static void ShowSeperatorRow(int labelWidth = 8)
{
labelWidth += 14;
Console.WriteLine(String.Empty.PadLeft(labelWidth, '*'));
}
}

View file

@ -4,18 +4,17 @@
{ {
static void Main(string[] args) static void Main(string[] args)
{ {
ShowSeperatorRow(); var place = new Places();
var label = "Navn"; place.PlaceName = "Stavern";
var fieldValue = "Stavern"; place.Municipality = "Larvik";
Console.WriteLine("Navn: Stavern"); place.Region = "Vestfold";
Console.WriteLine("Kommune: Larvik"); place.ShowPlace();
Console.WriteLine("Fylke: Vestfold"); var place2 = new Places();
ShowSeperatorRow(); place2.PlaceName = "Rjukan";
} place2.Municipality = "Tinn";
static void ShowSeperatorRow() place2.Region = "Telemark";
{ place2.ShowPlace();
Console.WriteLine("****************************");
} }
} }
} }