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

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