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.
Here is my program:
public class Person
{
public string Name { set { _name = value; } get { return _name; } }
public string Address { set { _address = value; } get { return _address; } }
public int Age { set { _age = value; } get { return _age; } }
private string _name;
private string _address;
private int _age;
}
public class PersonImplementation
{
public void GetName(IList<Person> person)
{
foreach(Person p in person)
{
Console.WriteLine(p.Name);
Console.WriteLine(p.Address);
}
}
public void Average(IList<Person> person)
{
int average = 0;
int r = 0;
double resaverage = 0;
foreach (Person p in person)
{
average += p.Age;
r++;
}
resaverage = average / r;
}
public void Max(IList<Person> person)
{
Console.WriteLine(person.Max());
}
}
Comments
Leave a comment