Nhận giá trị nhỏ nhất từ một chuỗi bằng cách sử dụng phương thức Min () trong C #.
Sau đây là danh sách của chúng tôi.
List<long> list = new List<long> { 1, 2, 3, 4, 5, 6 }; Bây giờ, hãy sử dụng phương thức Queryable Min () để nhận phần tử tối thiểu.
list.AsQueryable().Min();
Ví dụ
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);
}
}