Sum the string length in CSharp
Description
The following code shows how to sum the string length.
Example
//from w w w . ja v a2 s.c o m
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
public class MainClass {
public static void Main() {
string[] words = { "cherry", "apple", "blueberry" };
double totalChars = words.Sum(w => w.Length);
Console.WriteLine("There are a total of {0} characters in these words.", totalChars);
}
}
The code above generates the following result.