diff --git a/Emne 3/ObjekterIListe/ObjekterIListe/Person.cs b/Emne 3/ObjekterIListe/ObjekterIListe/Person.cs index 6910747..3180d7d 100644 --- a/Emne 3/ObjekterIListe/ObjekterIListe/Person.cs +++ b/Emne 3/ObjekterIListe/ObjekterIListe/Person.cs @@ -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; } } \ No newline at end of file diff --git a/Emne 3/ObjekterIListe/ObjekterIListe/Program.cs b/Emne 3/ObjekterIListe/ObjekterIListe/Program.cs index af66958..e3f9b5b 100644 --- a/Emne 3/ObjekterIListe/ObjekterIListe/Program.cs +++ b/Emne 3/ObjekterIListe/ObjekterIListe/Program.cs @@ -2,28 +2,15 @@ { class Program { - static public void AddPeople() + static void Main(string[] args) { - List people = new List(); - 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 people) - { - for (int i = 0; i < people.Count; i++) + List people = new List { - 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}")); } } } \ No newline at end of file