LINQ 学习路程 -- 查询操作 Average Count Max Sum
IList<int> intList = new List<int>>() { , ,  };
var avg = intList.Average();
Console.WriteLine("Average: {0}", avg);
IList<Student> studentList = new List<Student>>() {
        new Student() { StudentID = , StudentName = "John", Age = } ,
        new Student() { StudentID = , StudentName = "Moin",  Age =  } ,
        new Student() { StudentID = , StudentName = "Bill",  Age =  } ,
        new Student() { StudentID = , StudentName = "Ram" , Age = } ,
        new Student() { StudentID = , StudentName = "Ron" , Age =  }
    };
var avgAge = studentList.Average(s => s.Age);
Console.WriteLine("Average Age of Student: {0}", avgAge);
var totalAge = (from s in studentList
select s.age).Count();
int Count<TSource>(); int Count<TSource>(Func<TSource, bool> predicate);
IList<Student> studentList = new List<Student>>() {
        new Student() { StudentID = , StudentName = "John", Age = } ,
        new Student() { StudentID = , StudentName = "Moin",  Age =  } ,
        new Student() { StudentID = , StudentName = "Bill",  Age =  } ,
        new Student() { StudentID = , StudentName = "Ram" , Age = } ,
        new Student() { StudentID = , StudentName = "Mathew" , Age =  }
    };
var numOfStudents = studentList.Count();
Console.WriteLine("Number of Students: {0}", numOfStudents);
// Student collection
IList<Student> studentList = new List<Student>>() {
new Student() { StudentID = , StudentName = "John", Age = } ,
new Student() { StudentID = , StudentName = "Moin", Age = } ,
new Student() { StudentID = , StudentName = "Bill", Age = } ,
new Student() { StudentID = , StudentName = "Ram" , Age = } ,
new Student() { StudentID = , StudentName = "Mathew" , Age = }
}; var numOfStudents = studentList.Count(s => s.Age >= ); Console.WriteLine("Number of Students: {0}", numOfStudents);
IList<int> intList = new List<int>() { , , , , ,  };
var largest = intList.Max();
Console.WriteLine("Largest Element: {0}", largest);
var largestEvenElements = intList.Max(i => {
                                    if(i% == )
                                        return i;
                                    return ;
                                });
Console.WriteLine("Largest Even Element: {0}", largestEvenElements );
IList<Student> studentList = new List<Student>>() {
        new Student() { StudentID = , StudentName = "John", Age = } ,
        new Student() { StudentID = , StudentName = "Moin",  Age =  } ,
        new Student() { StudentID = , StudentName = "Bill",  Age =  } ,
        new Student() { StudentID = , StudentName = "Ram" , Age = } ,
        new Student() { StudentID = , StudentName = "Ron" , Age =  }
    };
var oldest = studentList.Max(s => s.Age);
Console.WriteLine("Oldest Student Age: {0}", oldest);
public class Student : IComparable<Student>
{
public int StudentID { get; set; }
public string StudentName { get; set; }
public int Age { get; set; }
public int StandardID { get; set; } public int CompareTo(Student other)
{
if (this.StudentName.Length >= other.StudentName.Length)
return ; return ;
}
}
class Program
{
    static void Main(string[] args)
    {
        // Student collection
        IList<Student> studentList = new List<Student>>() {
                new Student() { StudentID = 1, StudentName = "John", Age = 13} ,
                new Student() { StudentID = 2, StudentName = "Moin",  Age = 21 } ,
                new Student() { StudentID = 3, StudentName = "Bill",  Age = 18 } ,
                new Student() { StudentID = 4, StudentName = "Ram" , Age = 20} ,
                new Student() { StudentID = 5, StudentName = "Steve" , Age = 15 }
            };
        var studentWithLongName = studentList.Max();
        Console.WriteLine("Student ID: {0}, Student Name: {1}",
                                        .StudentID, studentWithLongName.StudentName)
    }
}
IList<int> intList = new List<int>() { , , , , ,  };
var total = intList.Sum();
Console.WriteLine("Sum: {0}", total);
var sumOfEvenElements = intList.Sum(i => {
                                    if(i% == )
                                        return i;
                                    return ;
                                });
Console.WriteLine("Sum of Even Elements: {0}", sumOfEvenElements );
IList<Student> studentList = new List<Student>>() {
        new Student() { StudentID = , StudentName = "John", Age = } ,
        new Student() { StudentID = , StudentName = "Moin",  Age =  } ,
        new Student() { StudentID = , StudentName = "Bill",  Age =  } ,
        new Student() { StudentID = , StudentName = "Ram" , Age = } ,
        new Student() { StudentID = , StudentName = "Ron" , Age =  }
    };
var sumOfAge = studentList.Sum(s => s.Age);
Console.WriteLine("Sum of all student's age: {0}", sumOfAge);
var numOfAdults = studentList.Sum(s => {
    if(s.Age >= )
        return ;
    else
        return ;
});
Console.WriteLine("Total Adult Students: {0}", numOfAdults);
LINQ 学习路程 -- 查询操作 Average Count Max Sum的更多相关文章
- LINQ 学习路程 --  查询操作 Aggregate
		
聚合操作执行数学的运算,如平均数.合计.总数.最大值.最小值 Method Description Aggregate 在集合上执行自定义聚集操作 Average 求平均数 Count 求集合的总数 ...
 - LINQ 学习路程 --  查询操作 Expression Tree
		
表达式树就像是树形的数据结构,表达式树中的每一个节点都是表达式, 表达式树可以表示一个数学公式如:x<y.x.<.y都是一个表达式,并构成树形的数据结构 表达式树使lambda表达式的结构 ...
 - LINQ 学习路程 --  查询操作 OrderBy & OrderByDescending
		
Sorting Operator Description OrderBy 通过给定的字段进行升序 降序 排序 OrderByDescending 通过给定字段进行降序排序,仅在方法查询中使用 Then ...
 - LINQ 学习路程 --  查询操作 Deferred Execution of LINQ Query 延迟执行
		
延迟执行是指一个表达式的值延迟获取,知道它的值真正用到. 当你用foreach循环时,表达式才真正的执行. 延迟执行有个最重要的好处:它总是给你最新的数据 实现延迟运行 你可以使用yield关键字实现 ...
 - LINQ 学习路程 --  查询操作 Join
		
Join操作是将两个集合联合 Joining Operators Usage Join 将两个序列连接并返回结果集 GroupJoin 根据key将两个序列连接返回,像是SQL中的Left Join ...
 - LINQ 学习路程 --  查询操作 where
		
1.where Filtering Operators Description Where Returns values from the collection based on a predicat ...
 - LINQ 学习路程 --  查询操作 GroupBy ToLookUp
		
Grouping Operators Description GroupBy GroupBy操作返回根据一些键值进行分组,每组代表IGrouping<TKey,TElement>对象 To ...
 - LINQ 学习路程 --  查询操作 let into关键字
		
IList<Student> studentList = new List<Student>() { , StudentName = } , , StudentName = } ...
 - LINQ 学习路程 --  查询操作 ElementAt, ElementAtOrDefault
		
Element Operators (Methods) Description ElementAt 返回指定索引的元素,如果索引超过集合长度,则抛出异常 ElementAtOrDefault 返回指定 ...
 
随机推荐
- Android各种模拟器使用笔记
			
[√]天天模拟器 优点: 缺点: 个人经验 ADB 版本过低的解决办法 去启动时的广告方法 去除多余进程方法 ADB无法连接到模拟器 原因分析: 解决方案: 安装APP(APK)时非常非常慢TTMNQ ...
 - u-boot README--Memory Management&initialize
			
Memory Management:------------------ U-Boot runs in system state and uses physical addresses, i.e. t ...
 - 如何搭建maven项目和搭建ssm框架
			
1.基本概念 1.1.Spring Spring是一个开源框架,Spring是于2003 年兴起的一个轻量级的Java 开发框架,由Rod Johnson 在其著作Expert One-On-One ...
 - 小图拼接大图MATLAB实现
			
小图拼接大图MATLAB实现 1.实现效果图 原图 效果图 2.代码 files = dir(fullfile('D:\document\GitHub\homework\digital image p ...
 - Sublime Text3 运行python(转)
			
From:http://blog.csdn.net/hun__ter/article/details/51223031 安装sublime text3后,按Ctrl+b无法运行python文件. 解决 ...
 - ICloneable接口 Clone 深拷贝 浅拷贝
			
需要字段本身也实现了深拷贝Clone.应用场景不多,意义不大. 1. 隐含式地要求其子类和引用类也要实现ICloneable接口,如果引用层次比较深类似一个网状或树形接口,增加复杂性. 2. 考虑给s ...
 - PHPUnit_Framework_Assert单元测试
			
先发下简书的干货: 教你一步一步写一个phpunit testcase:https://www.jianshu.com/p/ba6829a6f3ec 程序地址 https://github.com/y ...
 - 虚拟化构建二分图(BZOJ2080 题解+浅谈几道双栈排序思想的题)
			
虚拟化构建二分图 ------BZOJ2080 题解+浅谈几道双栈排序思想的题 本题的题解在最下面↓↓↓ 不得不说,第一次接触类似于双栈排序的这种题,是在BZOJ的五月月赛上. [BZOJ4881][ ...
 - ASP.NET中指定自定义HTTP响应标头
			
新建一个类HideServerHeaderHelper,继承 IHttpModule,然后重写 OnPreSendRequestHeaders,Dispose,Init方法,如下代码所示 using ...
 - Conductors(水题)
			
Conductors Background Everyone making translations from English to Russian knows an English phrase & ...