Create a class Person with attributes string Name, string Address and int age and define getter setter
method using Auto Implementation Property
• Create a class PersonImplementation and implement the below given methods:
1. GetName(IList<Person> person) display the name and address of all the persons in the List
2. Average(List<Player> players) to calculate the
average age of all the persons.
3. Max(IList<Player> players) to find the maximum age of the person.
class Person
{
public string Name { get; set; }
public string Address { get; set; }
public int Age { get; set; }
}
class PersonImplementation
{
public void GetName(IList<Person> persons)
{
foreach (Person person in persons)
{
Console.WriteLine($"{person.Name} - {person.Address}");
}
}
public void Average(List<Person> persons)
{
Console.WriteLine($"Average age of persons: {persons.Average(p => p.Age)}");
}
public void Max(IList<Person> persons)
{
Console.WriteLine($"Average age of persons: {persons.Max(p => p.Age)}");
}
}
Comments
Leave a comment