Return the total elements in a sequence as a 64-bit signed integer in C#


Firstly, set a string array.

string[] num = { "One", "Two", "Three", "Four", "Five"};

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

num.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[] num = { "One", "Two", "Three", "Four", "Five"};
      long res = num.AsQueryable().LongCount();
      Console.WriteLine("{0} elements", res);
   }
}

Output

5 elements

Updated on: 23-Jun-2020

58 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements