How to count the words in an array of strings using Linq in C#

1 Answer

0 votes
using System;
using System.Linq;

class Program
{
    static void Main() {
        string[] array = { "c-sharp", "c", "c++", "java python go", "php javascript" };
        
        var totalWords = array.SelectMany(e => e.Split(' ')).Count();
        
        Console.WriteLine(totalWords);
    }
}



/*
run:

8

*/

 



answered Jul 3, 2023 by avibootz
...