CSharp · Console
using System;
using System.Collections.Generic;
using System.Linq;
class Program
{
static void Main(string[] args)
{
DisplayDataFromFile();
}
private static void DisplayDataFromFile()
{
var people = PersonDataService.GetPeople().SkipWhile(p => p.FirstName.Contains("p"));
Console.WriteLine("PEOPLE READ FROM FILE:");
foreach (var person in people)
{
Console.WriteLine($"First: {person.FirstName}");
Console.WriteLine($"Last: {person.LastName}");
Console.WriteLine($"Phone: {person.Phone}");
Console.WriteLine($"Email: {person.EmailAddress}");
Console.WriteLine(Environment.NewLine);
}
}
}
class PersonDataService
{
public static List<PersonObj> GetPeople()
{
return new List<PersonObj>{new PersonObj{FirstName = "paul", LastName = "post", Phone = "(503) 393-3939", EmailAddress = "[email protected]"}, new PersonObj{FirstName = "mike", LastName = "sams", Phone = "(503) 434-3422", EmailAddress = "[email protected]"}};
}
}
public class PersonObj
{
public string FirstName
{
get;
set;
}
public string LastName
{
get;
set;
}
public string Phone
{
get;
set;
}
public string EmailAddress
{
get;
set;
}
}
public static class PersonHelper
{
/// <summary>
/// Return object from collection by name.
/// </summary>
/// <param name = "query"></param>
/// <param name = "name"></param>
/// <returns></returns>
public static IEnumerable<PersonObj> ByName(this IEnumerable<PersonObj> query, string name)
{
return query.Where(p => p.FirstName == name);
}
}