C# Queryable Min 方法


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

以下是我們的列表。

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

現在,使用 Queryable 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);
      }
      // getting lowest element
      long min_num = list.AsQueryable().Min();
      Console.WriteLine("Smallest number = {0}", mix_num);
   }
}

更新於:23-6 月-2020

107 次瀏覽

開啟你的 職業生涯

完成課程獲得認證

開始
廣告
© . All rights reserved.