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