使用 Lambda 表示式查詢陣列中最大元素的 C# 程式
宣告陣列 −
int[] arr = { 10, 90, 20, 19, 99, 57 };
現在要獲得陣列中最大的元素,請對 Lambda 表示式使用 Max() 方法 −
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
廣告