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