refactoring
This commit is contained in:
parent
0950feff85
commit
96c1b52110
30
Emne 3/StaticogIkkestatic/StaticogIkkestatic/Places.cs
Normal file
30
Emne 3/StaticogIkkestatic/StaticogIkkestatic/Places.cs
Normal 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, '*'));
|
||||||
|
}
|
||||||
|
}
|
|
@ -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("****************************");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue