I'm trying to loop through an ArrayList of objects of type (people) so i created two classes :
Person.cs
using System;
namespace GenericTypes
{
public class Person
{
public string FirstName { get; set; }
public string LastName { get; set; }
public int Age { get; set; }
public DateTime DateTime { get; set; }
}
}
People.cs
using System;
using System.Collections;
using System.Collections.Generic;
namespace GenericTypes
{
public class People
{
public ArrayList GetNonGenericPeople()
{
var people = new ArrayList()
{
new Person() {FirstName = "Djerah", LastName = "Ahmed Rafik", Age = 23, DateTime = DateTime.Today},
new Person() {FirstName = "Djerah", LastName = "Amjed Amir", Age = 11, DateTime = DateTime.Today},
new Person() {FirstName = "Gadda", LastName = "Anoir", Age = 25, DateTime = DateTime.Today}
};
return people;
}
public List<Person> GetGenericPeople()
{
var people = new List<Person>()
{
new Person() {FirstName = "Djerah", LastName = "Ahmed Rafik", Age = 23, DateTime = DateTime.Today},
new Person() {FirstName = "Djerah", LastName = "Amjed Amir", Age = 11, DateTime = DateTime.Today},
new Person() {FirstName = "Gadda", LastName = "Anoir", Age = 25, DateTime = DateTime.Today}
};
return people;
}
}
}
What i couldn't figure out is how to loop through GetNonGenericPeople() so can i output every object with it's properties
program.cs
namespace GenericTypes
{
class Program
{
static void Main(string[] args)
{
var persons = new People();
var p = persons.GetNonGenericPeople();
foreach (var s in p)
{
Console.WriteLine(s);
}
}
}
}