CSharp - Use Max operator on the last name of the actor

Description

Use Max operator on the last name of the actor

Demo

using System;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
class Program//from   w w  w .  j a v a 2 s  .  c  o  m
{
    static void Main(string[] args)
    {
        string lastAlphabetically = Actor.GetActors().Max(a => a.lastName);
        Console.WriteLine(lastAlphabetically);
    }
}
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