C# Linq Count method


The Count method returns the count of elements in a sequence.

Let us first set an array.

string[] arr = { "Java", "C++", "Python"};

Now, use the Count() method to count the array elements.

arr.AsQueryable().Count();

The following is the complete example.

Example

 Live Demo

using System;
using System.Linq;
using System.Collections.Generic;
class Demo {
   static void Main() {
      string[] arr = { "Java", "C++", "Python"};
      int arr_count = arr.AsQueryable().Count();
      Console.WriteLine("Count of arrays: {0}", arr_count);
   }
}

Output

Count of arrays: 3

Updated on: 23-Jun-2020

387 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements