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, '*'));
|
||||
}
|
||||
}
|
|
@ -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();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue