C# 可查询的 Min 方法

csharpprogrammingserver side programming更新于 2025/9/14 19:15:00

使用 C# 中的 Min() 方法从序列中获取最小值。

以下是我们的列表。

List<long> list = new List<long> { 1, 2, 3, 4, 5, 6 };

现在,使用可查询的 Min() 方法获取最小元素。

list.AsQueryable().Min();

示例

using System;
using System.Collections.Generic;
using System.Linq;
class Demo {
   static void Main() {
      List<long> list = new List<long> { 1, 2, 3, 4, 5, 6 };
      foreach(long ele in list) {
         Console.WriteLine(ele);
      }
      // 获取最低元素
      long min_num = list.AsQueryable().Min();
      Console.WriteLine("Smallest number = {0}", mix_num);
   }
}

相关文章