

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
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# Program to find the sum of a sequence
Firstly, set a sequence.
List<int> myList = new List<int> { 1, 2, 3, 4 ,5};
Now find the sum using the Queryable Sum() method.
myList.AsQueryable().Sum();
Example
using System; using System.Linq; using System.Collections.Generic; public class Demo { public static void Main() { List<int> myList = new List<int> { 1, 2, 3, 4 ,5}; Console.WriteLine("Sum of elements in a list..."); foreach (int res in myList) { Console.WriteLine(res); } int sum = myList.AsQueryable().Sum(); Console.WriteLine("Sum = {0}", sum); } }
Output
Sum of elements in a list... 1 2 3 4 5 Sum = 15
- Related Questions & Answers
- Program to find sum of given sequence in C++
- C# Program to find the average of a sequence of numeric values
- 8085 program to find the sum of a series
- C++ Program to Find the Longest Increasing Subsequence of a Given Sequence
- C++ Program to Find the Longest Prefix Matching of a Given Sequence
- C++ program to find sequence of indices of the team members
- Python Program to find the sum of array
- C Program to Find the minimum sum of factors of a number?
- Program to find sum of the sum of all contiguous sublists in Python
- Python program to find the sum of sine series
- Python program to find Cumulative sum of a list
- Program to find nth sequence after following the given string sequence rules in Python
- C++ Program to find out the distinct elements in a given sequence
- Program to find number of swaps required to sort the sequence in python
- Program to find length of longest consecutive sequence in Python
Advertisements