I'm trying to solve this problem:
I am working on a homework exercise that is printing info about citizens, and I am stuck on the part where I have to add the citizens to a list of the class Citizen
. I am getting an error when adding the created objects to a list (List<Citizen>
) I would want to print in the console:
No overload for method
Add
takes 3 arguments.
This is my code:
class Program
{
static void Main(string[] args)
{
List<Citizen> citizens = new List<Citizen>();
string name = Console.ReadLine();
string country = Console.ReadLine();
int age = int.Parse(Console.ReadLine());
citizens.Add(name,age,country);
string end = Console.ReadLine().ToUpper();
while (end!="End")
{
name = Console.ReadLine();
country = Console.ReadLine();
age = int.Parse(Console.ReadLine());
citizens.Add(name, age, country);
}
}
}
public interface IResident
{
public string Name { get;}
public string Country { get;}
public string GetName();
}
public interface IPerson
{
public string Name { get;}
public int Age { get;}
public string GetName();
}
public class Citizen : IPerson, IResident
{
public Citizen(string name, int age, string country)
{
this.Name = name;
this.Age = age;
this.Country = country;
}
public string Name { get; private set; }
public int Age { get; private set; }
public string Country { get; private set; }
string IPerson.GetName()
{
return $"{this.Name}";
}
string IResident.GetName()
{
return "Mr/Ms/Mrs ";
}
}