Lister er kult
This commit is contained in:
parent
12c164c6b3
commit
f186fcf653
|
@ -7,10 +7,10 @@ public class Person
|
||||||
public int Age { get; set; }
|
public int Age { get; set; }
|
||||||
|
|
||||||
// Constructor
|
// Constructor
|
||||||
public Person(string firstName, string lastName, int Age)
|
public Person(string firstName, string lastName, int age)
|
||||||
{
|
{
|
||||||
firstName = firstName;
|
FirstName = firstName;
|
||||||
lastName = lastName;
|
LastName = lastName;
|
||||||
Age = Age;
|
Age = age;
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -2,28 +2,15 @@
|
||||||
{
|
{
|
||||||
class Program
|
class Program
|
||||||
{
|
{
|
||||||
static public void AddPeople()
|
static void Main(string[] args)
|
||||||
{
|
{
|
||||||
List<Person> people = new List<Person>();
|
List<Person> people = new List<Person>
|
||||||
Person person1 = new Person("Alice", "Smith", 25);
|
|
||||||
Person person2 = new Person("Bob", "Jones", 37);
|
|
||||||
Person person3 = new Person("Charlie", "Jones", 28);
|
|
||||||
|
|
||||||
people.Add(person1);
|
|
||||||
people.Add(person2);
|
|
||||||
people.Add(person3);
|
|
||||||
WriteToConsole(people);
|
|
||||||
|
|
||||||
}
|
|
||||||
static void WriteToConsole(this List<Person> people)
|
|
||||||
{
|
{
|
||||||
for (int i = 0; i < people.Count; i++)
|
new Person("Alice", "Smith", 25),
|
||||||
{
|
new Person("Bob", "Jones", 37),
|
||||||
Console.WriteLine($"Fornavn: {people[i].FirstName}\nEtternavn: {people[i].LastName}\nAlder: {people[i].Age}");
|
new Person("Charlie", "Jones", 28)
|
||||||
}
|
};
|
||||||
}
|
people.ForEach(p => Console.WriteLine($"Navn: {p.FirstName} {p.LastName}\nAlder: {p.Age}"));
|
||||||
static void Main(string[] args){
|
|
||||||
AddPeople();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in a new issue