Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
C# Average Method
To find the average of integers in C#, use the Queryable Average() method.
Let’s say the following is our integer array.
var arr = new int[] { 10, 17, 25, 30, 40, 55, 60, 70 };
Now, use the Average() method to get the average of the elements.
double avg = Queryable.Average(arr.AsQueryable());
Example
using System;
using System.Linq;
class Demo {
static void Main() {
var arr = new int[] { 10, 17, 25, 30, 40, 55, 60, 70 };
double avg = Queryable.Average(arr.AsQueryable());
Console.WriteLine("Average = "+avg);
}
}
Output
Average = 38.375
Advertisements