How to get the last word from an array of strings with length of N using Linq in C#

1 Answer

0 votes
using System;
using System.Linq;

class Program
{
    static void Main() {
        string[] array = 
        { 
            "play", "sing", "sci", "fi", "game", "pro", "dev" , "five", 
            "moon", "c#", "net", "cool", "programming"
        };

        int length = 3;
        Console.WriteLine(array.Last(word => word.Length == length));
    }
}



/*
run:

net

*/

 



answered Jul 2, 2023 by avibootz
...