How to count the characters in a list of strings using Linq with C#

1 Answer

0 votes
using System;
using System.Linq;
using System.Collections.Generic;
  
class Program
{
    static void Main() {
        var list = new List<string> { "c-sharp", "c", "c++", "java", "python", "php" };
  
        var result = (from w in list select w.Length).Sum();
          
        Console.WriteLine(result);
    }
}
  
  
  
/*
run:
     
24
   
*/

 



answered Jul 5, 2023 by avibootz

Related questions

1 answer 127 views
1 answer 140 views
1 answer 129 views
1 answer 215 views
...