Lister er kult

This commit is contained in:
Geir Okkenhaug Jerstad 2024-11-25 14:07:06 +01:00
parent 12c164c6b3
commit f186fcf653
2 changed files with 11 additions and 24 deletions

View file

@ -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;
}
}

View file

@ -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)
List<Person> people = new List<Person>
{
for (int i = 0; i < people.Count; i++)
{
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}"));
}
}
}