Average length of the words in the string array in CSharp
Description
The following code shows how to average length of the words in the string array.
Example
using System;/*from w w w . j a v a 2s . c om*/
using System.Collections.Generic;
using System.Linq;
using System.Text;
public class MainClass {
public static void Main() {
string[] words = { "ch", "a", "blue" };
double averageLength = words.Average(w => w.Length);
Console.WriteLine("The average word length is {0} characters.", averageLength);
}
}
The code above generates the following result.