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

เมธอด LongCount ของ Queryable ใน C#

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

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

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

ผลลัพธ์

2 employees in the Department

ต่างจาก Count(): Count() คืน int ในขณะที่ LongCount() คืน long