声明一个数组-
int[] arr = { 10, 15, 5, 20};现在要从数组中获取最小的元素,请使用Min()具有lambda表达式的方法-
arr.Min());
这是完整的代码-
using System;
using System.Linq;
class Demo {
static void Main() {
int[] arr = { 10, 15, 5, 20};
Console.WriteLine(arr.Min(element => Math.Abs(element)));
}
}输出结果
5