C# 中的 Lambda 表示式
C# 中的一個 Lambda 表示式描述一個模式。
Lambda 表示式在表示式上下文中使用 => 令牌。在宣告 Lambda 表示式時將其讀作“傳遞到”運算子。
此處,我們正在從列表中查詢第一個大於 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
廣告
資料結構
網路
RDBMS
作業系統
Java
iOS
HTML
CSS
Android
Python
C 程式設計
C++
C#
MongoDB
MySQL
Javascript
PHP