In this article we will learn, how to use LINQ Sum() Function or what is LINQ Sum() Function C# Mvc with example.


In LINQ, The Sum() Function gives us the Sum of items in a collection or List. It is use to calculate the sum of items in a collection or List. LINQ has made it very easy to calculate the sum of items in a collection or List. Otherwise in our normal coding we have to write quite bit of code to get sum value from list of available values.


LINQ Sum() Function Example

Now we will see the example of using linq Sum() function to sum up items in collection / list.

using System;
using System.Collections.Generic;
using System.Linq;
namespace SQLTutorialsPoint
    class Program
        static void Main(string[] args)
            int[] Num = { 10, 20, 30};
            Console.WriteLine("Calculating the sum of all the elements of the array:");
            int Sum = Num.Sum();
            Console.WriteLine("The Sum is {0}",Sum);

When we execute above c# program, we will get the result like as shown below.

 how to use Sum function in linq c#

As you see above example we have a integer array “Num” and we will get sum of items value in given array using LINQ Sum() function.


I hope it will help to you after reading.



Leave a comment

Make sure you enter the (*) required information where indicated. HTML code is not allowed.

You may also like