นิพจน์แลมบ์ดาใน C# อธิบายรูปแบบ
Lambda Expressions มีโทเค็น => ในบริบทของนิพจน์ ค่านี้อ่านว่าตัวดำเนินการ "ไปที่" และใช้เมื่อมีการประกาศนิพจน์แลมบ์ดา
ในที่นี้ เรากำลังพบการเกิดขึ้นครั้งแรกขององค์ประกอบที่มากกว่า 50 จากรายการ
list.FindIndex(x => x > 50);
เหนือโทเค็น => ถูกใช้ ดังแสดงด้านล่าง −
ตัวอย่าง
using System;
using System.Collections.Generic;
class Demo {
static void Main() {
List<int> list = new List<int> { 44, 6, 34, 23, 78 };
int res = list.FindIndex(x => x > 50);
Console.WriteLine("Index: "+res);
}
} ผลลัพธ์
Index: 4