CSharp - Use Max operator with selector to find the latest actor birth year.

Description

Use Max operator with selector to find the latest actor birth year.

Demo

using System;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
class Program//from   w  w  w. j  a v a2s.  c o  m
{
    static void Main(string[] args)
    {
        int youngestActorAge = Actor.GetActors().Max(a => a.birthYear);
        Console.WriteLine(youngestActorAge);
    }
}
public class Actor
{
    public int birthYear;
    public string firstName;
    public string lastName;

    public static Actor[] GetActors()
    {
        Actor[] actors = new Actor[] {
           new Actor { birthYear = 1964, firstName = "Kotlin", lastName = "Ruby" },
           new Actor { birthYear = 1968, firstName = "Owen", lastName = "Windows" },
           new Actor { birthYear = 1960, firstName = "Javascript", lastName = "Spader" },
           new Actor { birthYear = 1964, firstName = "Scala", lastName = "Java" },
         };

        return (actors);
    }
}

Result

Related Topic