How to

get average number from collection

Published: 9. October 2011 | Updated: 9. October 2011
License: Microsoft Public License (MS-PL)
Categories: Collections » Linq, Framework » Math
Tags: C# Linq Math
Was this snippet helpful for you? YESYES / NONO

Import namespace

using System.Linq;

Code

int[] numbers = new[] { 5, 10, 30, 100 };

double avg = numbers.Average();

Console.WriteLine(avg);
Console Output:
36.25
Send us feedback about this snippet »



Related Snippets: