CSharp - Use Min operator with condition and selector

Description

Use Min operator with condition and selector

Demo

using System;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
class Program//  ww w. j av  a 2s .c  o m
{
    static void Main(string[] args)
    {

        string firstAlphabetically = Actor.GetActors().Min(a => a.lastName);

        Console.WriteLine(firstAlphabetically);
    }
}
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