
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# LINQ Sum Method
Find the sum of elements using the Linq Sum() method.
Here’s our list with integer elements.
List<int> list = new List<int> { 99, 34, 77, 75, 87, 35, 88};
Now find the sum using the Sum() method.
list.AsQueryable().Sum();
The following is an example to find the sum of elements of a list with integer elements.
Example
using System; using System.Linq; using System.Collections.Generic; public class Demo { public static void Main() { List<int> list = new List<int> { 99, 34, 77, 75, 87, 35, 88}; int res = list.AsQueryable().Sum(); Console.WriteLine("Sum = {0}", res); } }
Output
Sum = 495
Advertisements