- Trending Categories
- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- 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# Program to find the average of a sequence of numeric values
Use the Linq Average() method to find the average of a sequence of numeric values.
Firstly, set a sequence.
List<int> list = new List<int> { 5, 8, 13, 35, 67 };
Now, use the Queryable Average() method to get the average.
Queryable.Average(list.AsQueryable());
Example
using System; using System.Linq; using System.Collections.Generic; class Demo { static void Main() { List<int> list = new List<int> { 5, 8, 13, 35, 67 }; double avg = Queryable.Average(list.AsQueryable()); Console.WriteLine("Average = "+avg); } }
Output
Average = 25.6
Advertisements