How to get the first 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 = 
        { 
            "pro", "play", "sing", "sci", "fi", "game", "dev" , "five", 
            "moon", "c#", "net", "cool", "programming"
        };
 
        int length = 4;
        Console.WriteLine(array.First(word => word.Length == length));
    }
}
 
 
 
/*
run:
 
play
 
*/

 



answered Jul 2, 2023 by avibootz
edited Jul 2, 2023 by avibootz
...