I have a foreach loop and I would like to call all properties of a certain class in the foreach loops so I don't have to write it all out.
The class I have created
public Person()
{
firstname = "";
surname = "";
haircolor = "";
eyecolor = "";
weight = 0;
height = 0;
age = 0;
}
This is the code I am trying to compact
Console.WriteLine("Please enter the next persons firstname");//new person user input (firstname)
addperson.firstname = Console.ReadLine();
Console.WriteLine("Enter the persons surname");//surname
addperson.surname = Console.ReadLine();
Console.WriteLine("Enter " + addperson.name + "'s hair color");//hair color
addperson.haircolor = Console.ReadLine();
Console.WriteLine("Enter the age of " + addperson.firstname);//age
addperson.age = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("Enter the weight of " + addperson.firstname);//weight
addperson.weight = Convert.ToDouble(Console.ReadLine());
Console.WriteLine("Enter the height of " + addperson.firstname);//height
addperson.height = Convert.ToDouble(Console.ReadLine());
I have started on the foreach loop, I would like a way to compact all of that code to a loop
foreach (Person.)
{
Console.WriteLine("Please enter " +addperson.ToString);
Person.addperson = Console.ReadLine();
}
Any help would be much appreciated