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

CsharpProgrammingServer Side Programming

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
raja
Published on 11-Sep-2018 15:49:27
Advertisements