Mega Code Archive

 
Categories / C# Book / 04 LINQ
 

0501 Sum - Projection

public void Linq79() { 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); } Result There are a total of 20 characters in these words.