C# Linq Count method

CsharpProgrammingServer Side Programming

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
raja
Published on 14-Sep-2018 16:38:48
Advertisements