Click here to Skip to main content
15,906,335 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
This is my code
C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace LamdaExpressionExamples
{

    class Person
    {
        public string SSN {get;set;}
        public string Name{get;set;}
        public string Address{get;set;}
        public int Age { get; set; }

        public Person(string ssn, string name, string addr, int age)
        {
            SSN = ssn;
            Name = name;
            Address = addr;
            Age = age;
        }
    }

    class Program
    {
        static void Main(string[] args)
        {
            List<Person> listPersonsInCity = new List<Person>();

            listPersonsInCity.Add(new Person("203456876", "John", "12 Main Street, Newyork, NY", 15));
            listPersonsInCity.Add(new Person("203456877", "SAM", "13 Main Ct, Newyork, NY", 25));
            listPersonsInCity.Add(new Person("203456878", "Elan", "14 Main Street, Newyork, NY", 35));
            listPersonsInCity.Add(new Person("203456879", "Smith", "12 Main Street, Newyork, NY", 45));
            listPersonsInCity.Add(new Person("203456880", "SAM", "345 Main Ave, Dayton, OH", 55));
            listPersonsInCity.Add(new Person("203456881", "Sue", "32 Cranbrook Rd, Newyork, NY", 65));
            listPersonsInCity.Add(new Person("203456882", "Winston", "1208 Alex St, Newyork, NY", 65));
            listPersonsInCity.Add(new Person("203456883", "Mac", "126 Province Ave, Baltimore, NY", 85));
            listPersonsInCity.Add(new Person("203456884", "SAM", "126 Province Ave, Baltimore, NY", 95));

            foreach(var list in listPersonsInCity)
            {
                Console.WriteLine(list.ToString());
            }

}
}



But this will not display my data so please tell me how to display in console application ?
Posted
Comments
Prasad Avunoori 30-May-14 3:04am    
Change your foreach loop as below solution1.

1 solution

C#
foreach (var list in listPersonsInCity)
            {
                Console.WriteLine(list.Name + "\t" + list.SSN + "\t" + list.Age + "\t" + list.Address);
            }
 
Share this answer
 
Comments
DGKumar 30-May-14 3:12am    
Thank you very much Noe the data is displaying.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900