Sử dụng phương thức Linq LongCount để tính số phần tử.
Sau đây là mảng chuỗi của chúng tôi -
string[] emp = { "Jack", "Mark"}; Bây giờ, hãy sử dụng phương thức LongCount ().
emp.AsQueryable().LongCount();
Đây là mã hoàn chỉnh.
Ví dụ
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);
}
} Đầu ra
2 employees in the Department