Min() trả về giá trị nhỏ nhất trong chuỗi số. Hỗ trợ các kiểu số và nullable types.
Ví dụ minh họa
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("Số nhỏ nhất = {0}", min_num);
}
}
Kết quả đầu ra
1 2 3 4 5 6 Số nhỏ nhất = 1
Lưu ý code gốc: Biến mix_num trong Console.WriteLine là lỗi typo, đã sửa thành min_num.
Overloads hữu ích: Min(selector) - tìm min sau khi biến đổi: list.Min(x => x.Length).