Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7437571
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T10:25:09+00:00 2026-05-29T10:25:09+00:00

I created a List called people that holds an identification number, name, title, and

  • 0

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);
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T10:25:09+00:00Added an answer on May 29, 2026 at 10:25 am

    your people list is currently empty at the beginning

    You would want to add your p1, p2, p3 and p4 to the people list

    Person p1 = new Person(74, 'Brad', 'Millington', 'Program Manager', 'Milford');
    people.add(p1);
    

    Then in your for each if you are printing them out i assume you have a getter for the name

    foreach (Person p in people) 
    {
        Console.Write(p.getFirstName() + ' ' + p.getLastName());
    }
    

    I have not done any C# myself but this should work based on my experience with Java

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have created a content type called Event. For each event, I would like
I created the list that have device detected, and I want to send data
I have created a list view that displays the names and dates of items
I have created a list form that gets attached to a main form in
I have a gridview and in that gridview i created a list of imagebuttons
I have a MySQL database called People which contains the following schema <id,name,foodchoice1,foodchoice2> .
So I have created a List of a Custom Class called FinalPixel , and
I'd like to create a simple reference app that lists a group of people,
I'm currently helping build an API that I would like 3rd party developers to
I have a dynamically created list. Items from the list should be able to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.