ใช้วิธี Linq LongCount เพื่อรับการนับองค์ประกอบ
ต่อไปนี้เป็นสตริงอาร์เรย์ของเรา -
string[] emp = { "Jack", "Mark"}; ตอนนี้ ใช้วิธี LongCount()
emp.AsQueryable().LongCount();
นี่คือรหัสที่สมบูรณ์
ตัวอย่าง
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