class Person
{
public string
FirstName { get; set; }
public string LastName
{ get; set; }
public string FullName
{ get => $"{FirstName} {LastName}"; }
public Person(string
FirstName, string LastName)
{
this.LastName = LastName;
this.FirstName = FirstName;
}
}
class People
{
IEnumerable<Person> _people;
Person nullPerson = new Person("No ", "Person");
public People(params Person[]
people) => _people = people;
public Person GetPerson(string Name)
=> _people.FirstOrDefault(p =>
p.FirstName == Name) ?? nullPerson;
}
Now when we take a look at our main class.
class Program
{
static void Main(string[] args)
{
var tomek = new Person("Tomek", "Chooch");
var marin = new Person("Marin", "Smartzik");
var people = new
People(pawel, tomek, marin);
Console.WriteLine(people.GetPerson("Tomek").FullName);
Console.WriteLine(people.GetPerson("Magda").FullName);
}
}