C# Queryable LongCount Method


Use the Linq LongCount method to get the count of elements.

The following is our string array −

string[] emp = { "Jack", "Mark"};

Now, use the LongCount() method.

emp.AsQueryable().LongCount();

Here is the complete code.

Example

 Live Demo

using System;
using System.Collections.Generic;
using System.Linq;
class Demo {
   static void Main() {
      string[] emp = { "Jack", "Mark"};
      long res = emp.AsQueryable().LongCount();
      Console.WriteLine("{0} employees in the Department", res);
   }
}

Output

2 employees in the Department

Updated on: 23-Jun-2020

112 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements