//Lambda,查询单个元素
int[] arr = { 234, 54, 34, 54, 34, 65, 345, 654, 3 };
Console.WriteLine("所有元素");
foreach (var item in arr)
{
Console.Write(item + " ");
}
Console.Write("\n");
Console.WriteLine("SingleOrDefault,查询单个元素");
var query = arr.SingleOrDefault(num => num == 3);
Console.WriteLine(query);
Console.WriteLine("Lambda where查询大于等于54的元素");
var query2 = arr.Where(num => num >= 54);
foreach (var item in query2)
{
Console.WriteLine(item);
}
Lambda的SingleOrDefault与Where方法详解
最新推荐文章于 2024-08-28 15:02:44 发布