Computer >> บทช่วยสอนคอมพิวเตอร์ >  >> การเขียนโปรแกรม >> C#

ส่งคืนจำนวนองค์ประกอบในลำดับเป็นจำนวนเต็ม 64 บิตใน C#

เมธอด LongCount() ใน LINQ คืนจำนวนองค์ประกอบในลำดับเป็น long (Int64) เหมาะสำหรับลำดับที่มีจำนวนมากเกินกว่า int.MaxValue

ตัวอย่างโค้ด

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);
    }
}

ผลลัพธ์

5 elements

เมื่อไหร่ควรใช้: ข้อมูลขนาดใหญ่ (Big Data) ที่จำนวนรายการอาจเกิน 2,147,483,647 รายการ