เมธอด Any(
ตัวอย่าง
static void Main(string[] args){ IEnumerable<double> doubles = new List<double> { 1.2, 1.7, 2.5, 2.4 }; bool result = doubles.Any(val => val < 1); System.Console.WriteLine(result); IEnumerable<double> doubles1 = new List<double> { 0.8, 1.7, 2.5, 2.4 }; bool result1 = doubles1.Any(val => val < 1); System.Console.WriteLine(result1); Console.ReadLine(); }
ผลลัพธ์
False True
ตัวอย่าง
static void Main(string[] args){ IEnumerable<double> doubles = new List<double> { 0.8, 0.9, 0.6, 0.7 }; bool result = doubles.All(val => val < 1); System.Console.WriteLine(result); IEnumerable<double> doubles1 = new List<double> { 0.8, 0.9, 1.0, 0.7 }; bool result1 = doubles1.All(val => val < 1); System.Console.WriteLine(result1); Console.ReadLine(); }
ผลลัพธ์
True False