包括下面七种:
Count
Sum
Max
Min
Average
Aggregate
LongCount
或者计算序列满足一定条件的元素的数量。
计算元素数量操作Count private void Count_Op() { List<OA_User> User = new List<OA_User>(); for (int i = 0; i < 10; i++) { user.Add(new OA_User(i,"Bjz" + i.ToString())); } int count = User.Count;//不加条件,Response.Write("User.Count=" + count.ToString()); int count_2 = User.Count(i => i.UserId > 3 && i.UserId < 8);//加条件 Response.Write("User.Count=" + count_2.ToString()); } 求和操作Sum private void Sum_Op() { List<OA_User> User = new List<OA_User>(); for (int i = 0; i < 10; i++) { user.Add(new OA_User(i,"Bjz" + i.ToString())); } int Sum = User.Sum(i => i.UserId);//不加条件 Response.Write("User.Sum=" + Sum.ToString()); int Sum_2 = User.Where(i => i.UserId > 3 && i.UserId < 8).Sum(i => i.UserId);//加条件 Response.Write("User.Sum=" + Sum.ToString()); } 最大值操作Max private void Max_Op() { List<OA_User> User = new List<OA_User>(); for (int i = 0; i < 10; i++) { user.Add(new OA_User(i,"Bjz" + i.ToString())); } int MAx = User.Max(i => i.UserId);//不加条件 Response.Write("User.Max=" + MAx.ToString()); int Max_2 = User.Where(i => i.UserId > 7).Max(i=>i.UserId);//加条件 Response.Write("User.Max_2=" + Max_2.ToString()); } 最小值操作Min private void Min_Op() { List<OA_User> User = new List<OA_User>(); for (int i = 0; i < 10; i++) { user.Add(new OA_User(i,"Bjz" + i.ToString())); } int Min = User.Min(i => i.UserId);//不加条件 Response.Write("User.Min=" + Min.ToString()); int Min_2 = User.Where(i => i.UserId > 7).Min(i => i.UserId);//加条件 Response.Write("User.Min_2=" + Min_2.ToString()); } 平均值操作Averge private void Average_Op() { List<OA_User> User = new List<OA_User>(); for (int i = 0; i < 10; i++) { user.Add(new OA_User(i,"Bjz" + i.ToString())); } double average = User.Average(i => i.UserId); Response.Write("User.Average=" + average.ToString()); }