linq之all
public static bool All<TSource>( this IEnumerable<TSource> source, Func<TSource, bool> predicate )
1 void testLinq2() 2 { 3 Func<int, bool> testAlldege = a=> 4 { 5 if (a>0) 6 { 7 return true; 8 } 9 else 10 { return false; } 11 }; 12 13 if(listNum.All(i=>i>0)) 14 { 15 MessageBox.Show("all big two"); 16 } 17 if (listNum.All(testAlldege)) 18 { 19 MessageBox.Show("all big two"); 20 } 21 }
传入一个返回bool的委托,来判断是不是所有的选项符合所要求的表达 式。