I have 3 problems with this code and I wanted to ask for a little help.
I seem to get an error message every time in person2 that a local variable named myAge and DateOfBirth is already defined in this scope? How can this be?
My second problem is that i cant seem to get the timestamp removed from the players date of birth.. I only need the date and not a timestamp?
My third and last problem is that all of the code won't display in the cmd.exe at the same time? I have to press enter to show the next player, but i want all players to be displayed at the same time?
Can anyone be of help? Thank you in advance!
public enum Gendertype { Male, Female };
public class Person
{
public string FirstName { get; set; }
public string MiddleName { get; set; }
public string LastName { get; set; }
public DateTime DateOfBirth { get; set; }
public string Nationality { get; set; }
public Gendertype Gender { get; set; }
public Person(string fn, string mn, string ln, DateTime dob, string n, Gendertype g)
{
FirstName = fn;
MiddleName = mn;
LastName = ln;
DateOfBirth = dob;
Nationality = n;
Gender = g;
}
}
class Program
{
static void Main()
{
Person person1 = new Person("Rafael" + "\n", "" + "\n", "Nadal" + "\n", new DateTime(1986,06, 03), "Spanish" + "\n", Gendertype.Male);
Console.WriteLine("Player 1: \n First name = {0} Middle name = {1 } Last name = {2} Date of birth = {3} \n Nationality = {4} Gender = {5}", person1.FirstName, person1.MiddleName, person1.LastName, person1.DateOfBirth, person1.Nationality, person1.Gender);
DateTime DateOfBirth = DateTime.Parse("1986/06/03");
TimeSpan myAge = DateTime.Now.Subtract(DateOfBirth);
Console.WriteLine(" Age:");
Console.WriteLine(myAge.TotalDays/365);
Console.ReadLine();
Person person2 = new Person("Rafael" + "\n", "" + "\n", "Nadal" + "\n", new DateTime(1988, 07, 04), "Spanish" + "\n", Gendertype.Male);
Console.WriteLine("Player 2: \n First name = {0} Middle name = {1 } Last name = {2} Date of birth = {3} \n Nationality = {4} Gender = {5}", person2.FirstName, person2.MiddleName, person2.LastName, person2.DateOfBirth, person2.Nationality, person2.Gender);
DateTime dob = DateTime.Parse("1988/07/04");
TimeSpan Age = DateTime.Now.Subtract(DateOfBirth);
Console.WriteLine(" Age:");
Console.WriteLine(myAge.TotalDays / 365);
Console.ReadLine();
person2.FirstName = "Molly";
Console.WriteLine("Player 2: \n First name = {0} Middle name = {1 } Last name = {2} Date of birth = {3} \n Nationality = {4} Gender = {5}", person1.FirstName, person1.MiddleName, person1.LastName, person1.DateOfBirth, person1.Nationality, person1.Gender);
Console.WriteLine("person1 Name = {0} Age = {1}", person2.FirstName, person2.DateOfBirth);
Console.WriteLine("Press any key to exit.");
Console.ReadKey();
}
}
}