using System;
using System.Collections.Generic;
class Program
{
static void Main()
{
List<int> numbers = new List<int> { 1, 2, 3, 4, 5 };
// 使用 Find 方法查找第一个满足条件的元素
int? result = numbers.Find(n => n > 3);
if (result != null)
{
Console.WriteLine("找到的第一个大于3的数字是: " + result);
}
else
{
Console.WriteLine("没有找到符合条件的元素");
}
}
}
List<T>.Find 方法用于查找列表中第一个满足指定条件的元素。numbers。Find 方法和 lambda 表达式 n => n > 3 查找列表中第一个大于 3 的元素。上一篇:c# task和thread区别
下一篇:c# int转string
Laravel PHP 深圳智简公司。版权所有©2023-2043 LaravelPHP 粤ICP备2021048745号-3
Laravel 中文站