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
广告
数据结构
网络
关系型数据库管理系统
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP