I created a List called people that holds an identification number, name, title, and city. I would like to automate the reading out of this list using a foreach but am a little stuck on the syntax. Can someone shed a little light on it. Below is my code.
List<Person> people = new List<Person>();
Person p1 = new Person(74, "Brad","Millington","Program Manager", "Milford");
Person p2 = new Person(58, "John", "Kaufman", "Author", "Ottawa");
Person p3 = new Person(68, "-*", "Washington" , "Developer", "Redmond");
Person p4 = new Person(79, "Abraham", "Licoln", "Developer", "Redmond");
foreach (string s in people)
{
people.Add(s);
}
your people list is currently empty at the beginning
You would want to add your p1, p2, p3 and p4 to the people list
Then in your for each if you are printing them out i assume you have a getter for the name
I have not done any C# myself but this should work based on my experience with Java