ใช้เมธอด First() เพื่อรับองค์ประกอบแรกจากอาร์เรย์
ขั้นแรก ตั้งค่าอาร์เรย์
int[] arr = {20, 40, 60, 80 , 100};
ตอนนี้ ใช้เมธอด Queryable First() เพื่อส่งคืนองค์ประกอบแรก
arr.AsQueryable().First();
ต่อไปนี้เป็นตัวอย่างทั้งหมด
ตัวอย่าง
using System; using System.Linq; using System.Collections.Generic; class Program { static void Main() { int[] arr = {20, 40, 60, 80 , 100}; // getting the first element int res = arr.AsQueryable().First(); Console.WriteLine(res); } }
ผลลัพธ์
20