รับค่าต่ำสุดจากลำดับโดยใช้วิธี Min() ใน C#
ต่อไปนี้เป็นรายการของเรา
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);
}
}