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