uses Average to get the average length of the words in the string array. : Average « LINQ « C# / C Sharp






uses Average to get the average length of the words in the string array.

 
using System;
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);
    }
}

 








Related examples in the same category

1.uses Average to get the average of all values of an integer array.
2.Average with int array
3.Grouped Average
4.Use Average method to calculate the average value from a query