一、创建数据
- (1)、数据源1
- (2)、数据源2
二、普通使用方法 - (1)ALL 和 ANY
bool allChina = products.All(p => p.Region == "中国");//所有项Region都要是中国,结果:False
bool anyChina = products.Any(p => p.Region == "中国");//某一项Region是中国,结果:True
- (2)聚集
int countIdGreater5 = products.Count(p => p.ID > 5);//ID大于5的记录数,结果:4
decimal maxPrice = products.Max(p => p.Price);//金额最高,结果:208000
int minId = products.Min(p => p.ID);//编号最小,结果:1
decimal avgPrice = products.Average(p => p.Price);//金额平均值,结果:53538
decimal sumPrice = products.Sum(p => p.Price);//金额总值 结果:481842
- (3)累加器
Product aggregate1 = products.Aggregate((total, next)