วิธีการ Count จะคืนค่าการนับขององค์ประกอบตามลำดับ
เรามาตั้งค่าอาร์เรย์กันก่อน
string[] arr = { "Java", "C++", "Python"}; ตอนนี้ ใช้วิธี Count() เพื่อนับองค์ประกอบอาร์เรย์
arr.AsQueryable().Count();
ต่อไปนี้เป็นตัวอย่างที่สมบูรณ์
ตัวอย่าง
using System;
using System.Linq;
using System.Collections.Generic;
class Demo {
static void Main() {
string[] arr = { "Java", "C++", "Python"};
int arr_count = arr.AsQueryable().Count();
Console.WriteLine("Count of arrays: {0}", arr_count);
}
} ผลลัพธ์
Count of arrays: 3