CSharp - Use selector with Min operator to select field to be used

Description

Use selector with Min operator to select field to be used

Demo

using System;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
class Program//from   w w  w  .ja v  a 2s .c  o  m
{
    static void Main(string[] args)
    {
        int oldestActorAge = Actor.GetActors().Min(a => a.birthYear);
        Console.WriteLine(oldestActorAge);

    }
}
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