linq Average
linq Average
This sample uses Average to get the average of all numbers in an array.public static void Average() { // Average - Simple int[] numbers = { 5, 4, 1, 3, 9, 8, 6, 7, 2, 0 }; double averageNum = numbers.Average(); Console.WriteLine("The average number is {0}.", averageNum); // Average - Projection string[] words = { "cherry", "apple", "blueberry" }; double averageLength = words.Average(w => w.Length); Console.WriteLine("The average word length is {0} characters.", averageLength); }
Output
linq Average
Reviewed by Bhaumik Patel
on
6:34 PM
Rating: