usingSystem.Collections.Generic;usingSystem.Linq;//intのListを生成List<int> list =newList<int>(){7,3,9,3,5,3};//要素の全てが5以上であるか判定するbool b = list.All(x => x >=5);
結果
false
例2)Dictionary型の場合
usingSystem.Collections.Generic;usingSystem.Linq;//Dictioinaryの生成Dictionary<string,string> dc =newDictionary<string,string>();
dc.Add("01","大阪市");
dc.Add("02","京都市");
dc.Add("03","神戸市");//Value値の全要素に"市"が含まれるか判定するbool b = dc.All(x => x.Value.Contains("市"));
結果
true
例3)データクラスListの場合
usingSystem.Collections.Generic;usingSystem.Linq;//データクラス(Prefクラス)classPref{publicint No {get;set;}publicstring Name {get;set;}publicint Population {get;set;}}//PrefのListを生成var list =newList<Pref>();
list.Add(newPref{No=1, Name="北海道", Population=5381733});
list.Add(newPref{No=2, Name="青森県", Population=1308265});
list.Add(newPref{No=3, Name="岩手県", Population=1279594});
list.Add(newPref{No=2, Name="青森県", Population=1308265});
list.Add(newPref{No=3, Name="岩手県", Population=1279594});//Pref.Populationが全て100万以上であるか判定するbool b = list.All(x => x.Population >=1000000);