C#可查询的最大方法
使用Max()方法从序列中获取最大值。
假设以下是我们的列表。
List<long> list = new List<long> { 200, 400, 600, 800, 1000, 1200, 1400, 1600, 1800, 2000 };使用该Max()方法获得最大的元素。
list.AsQueryable().Max();
示例
using System;
using System.Collections.Generic;
using System.Linq;
class Demo {
static void Main() {
List<long> list = new List<long> { 200, 400, 600, 800, 1000, 1200, 1400, 1600, 1800, 2000 };
foreach(long ele in list)
Console.WriteLine(ele);
//得到最大的元素
long max_num = list.AsQueryable().Max();
Console.WriteLine("Largest number = {0}", max_num);
}
}输出结果
200 400 600 800 1000 1200 1400 1600 1800 2000 Largest number = 2000