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



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


LINQ Count() Function Example

Now we will see the example of using linq Count() function to count number of 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, 40, 50, 60, 70, 80, 90 };
            Console.WriteLine("Find the count of the elements:");
            int Count = Num.Count();
            Console.WriteLine("The Count is {0}", Count);



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

 how to use Count function in linq c#

As you see above example we have a integer array “Num” and we will get total number of items/elements in given array using LINQ Count() 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