How to use Linq query on string array to get strings that start with specific letter in C#

1 Answer

0 votes
using System;
using System.Linq;

class Program
{
    static void Main() {
        string[] arr = { "c#", "java", "python", "c++", "swift" };
        var Query = from word in arr
                    where word[0] == 'c'
                    select word;


        foreach (string s in Query) {
            Console.WriteLine(s);
        }
    }
}



/*
run:

c#
c++

*/

 



answered Nov 22, 2020 by avibootz
...