LINQ 学习路程 -- 查询操作 Conversion Operators
| Method | Description | 
|---|---|
| AsEnumerable | Returns the input sequence as IEnumerable<t> | 
| AsQueryable | Converts IEnumerable to IQueryable, to simulate a remote query provider | 
| Cast | Coverts a non-generic collection to a generic collection (IEnumerable to IEnumerable<T>) | 
| OfType | Filters a collection based on a specified type | 
| ToArray | Converts a collection to an array | 
| ToDictionary | Puts elements into a Dictionary based on key selector function | 
| ToList | Converts collection to List | 
| ToLookup | Groups elements into an Lookup<TKey,TElement> | 
class Program
{ static void ReportTypeProperties<T>(T obj)
{
Console.WriteLine("Compile-time type: {0}", typeof(T).Name);
Console.WriteLine("Actual type: {0}", obj.GetType().Name);
} static void Main(string[] args)
{
Student[] studentArray = {
new Student() { StudentID = , StudentName = "John", Age = } ,
new Student() { StudentID = , StudentName = "Steve", Age = } ,
new Student() { StudentID = , StudentName = "Bill", Age = } ,
new Student() { StudentID = , StudentName = "Ram" , Age = } ,
new Student() { StudentID = , StudentName = "Ron" , Age = } ,
}; ReportTypeProperties( studentArray);
ReportTypeProperties(studentArray.AsEnumerable());
ReportTypeProperties(studentArray.AsQueryable());
}
} Cast
class Program
{
    static void ReportTypeProperties<T>(T obj)
    {
        Console.WriteLine("Compile-time type: {0}", typeof(T).Name);
        Console.WriteLine("Actual type: {0}", obj.GetType().Name);
    }
    static void Main(string[] args)
    {
        Student[] studentArray = {
                new Student() { StudentID = 1, StudentName = "John", Age = 18 } ,
                new Student() { StudentID = 2, StudentName = "Steve",  Age = 21 } ,
                new Student() { StudentID = 3, StudentName = "Bill",  Age = 25 } ,
                new Student() { StudentID = 4, StudentName = "Ram" , Age = 20 } ,
                new Student() { StudentID = 5, StudentName = "Ron" , Age = 31 } ,
            };   
        ReportTypeProperties( studentArray);
        ReportTypeProperties(studentArray.Cast<Student>());
    }
}      
IList<string> strList = new List<string>() {
                                            "One",
                                            "Two",
                                            "Three",
                                            "Four",
                                            "Three"
                                            };
string[] strArray = strList.ToArray<string>();// converts List to Array
IList<string> list = strArray.ToList<string>(); // converts array into list
IList<Student> studentList = new List<Student>() {
                    new Student() { StudentID = 1, StudentName = "John", age = 18 } ,
                    new Student() { StudentID = 2, StudentName = "Steve",  age = 21 } ,
                    new Student() { StudentID = 3, StudentName = "Bill",  age = 18 } ,
                    new Student() { StudentID = 4, StudentName = "Ram" , age = 20 } ,
                    new Student() { StudentID = 5, StudentName = "Ron" , age = 21 }
                };
//following converts list into dictionary where StudentId is a key
IDictionary<int, Student> studentDict =
                                studentList.ToDictionary<Student, int>(s => s.StudentID); 
foreach(var key in studentDict.Keys)
	Console.WriteLine("Key: {0}, Value: {1}",
                                key, (studentDict[key] as Student).StudentName);LINQ 学习路程 -- 查询操作 Conversion Operators的更多相关文章
- LINQ 学习路程 --  查询操作 Quantifier Operators All Any Contain
		Operator Description All 判断所有的元素是否满足条件 Any 判断存在一个元素满足条件 Contain 判断是否包含元素 IList<Student> studen ... 
- LINQ 学习路程 --  查询操作 Expression Tree
		表达式树就像是树形的数据结构,表达式树中的每一个节点都是表达式, 表达式树可以表示一个数学公式如:x<y.x.<.y都是一个表达式,并构成树形的数据结构 表达式树使lambda表达式的结构 ... 
- LINQ 学习路程 --  查询操作 Join
		Join操作是将两个集合联合 Joining Operators Usage Join 将两个序列连接并返回结果集 GroupJoin 根据key将两个序列连接返回,像是SQL中的Left Join ... 
- LINQ 学习路程 --  查询操作 OrderBy & OrderByDescending
		Sorting Operator Description OrderBy 通过给定的字段进行升序 降序 排序 OrderByDescending 通过给定字段进行降序排序,仅在方法查询中使用 Then ... 
- 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 学习路程 --  查询操作 Deferred Execution of LINQ Query 延迟执行
		延迟执行是指一个表达式的值延迟获取,知道它的值真正用到. 当你用foreach循环时,表达式才真正的执行. 延迟执行有个最重要的好处:它总是给你最新的数据 实现延迟运行 你可以使用yield关键字实现 ... 
- LINQ 学习路程 --  查询操作 let into关键字
		IList<Student> studentList = new List<Student>() { , StudentName = } , , StudentName = } ... 
- LINQ 学习路程 --  查询操作 Distinct  Except Intersect Union
		Set Operators Usage Distinct 去掉集合的重复项 Except 返回两个集合的不同,第一个集合的元素不能出现在第二个集合中 Intersect 返回两个集合的交集,即元素同时 ... 
随机推荐
- URL检测脚本
			#!/bin/bash# filename : 8_5_1.sh function usage(){ echo "usage:$0 url" exit 1} function ch ... 
- warning: push.default is unset; its implicit value is changing in Git 2.0 from 'matching' to 'simple'.
			'matching'参数是 git 1.x 的默认行为,其意是如果你执行 git push 但没有指定分支,它将 push 所有你本地的分支到远程仓库中对应匹配的分支. 而 Git 2.x 默认的是 ... 
- PHP压缩上传图片
			最近手上的项目页面要显示很多图片,虽然用了jQuery的lazyload,但是效果并没理想,滑动到一个区域还要比较长的时间图片才完全显示出来.于是想着将上传上去的900KB+压缩备份一份缩略图. PH ... 
- sublime使用技巧(3)-- 常用快捷键【持续更新】
			♥ Ctrl + Shift + v 这样粘贴可以保持原格式,不会有缩进上的困扰 Ctrl + k 用Ctrl + d选中重复单词时跳过当前选中 Ctrl + Enter 在光标所在行的下一行新建一行 ... 
- maven   依赖文件 pom.xml   编译 mvn compile         运行 不用mvn exec:java -Dexec.mainClass="hello.HelloWorld"    打成jar包 mvn package   mvn install   http://blog.csdn.net/yaya1943/article/details/48464371
			使用maven编译Java项目 http://blog.csdn.net/yaya1943/article/details/48464371 使用"mvn clean"命令清除编 ... 
- mysql导出数据库提示警告在GTID模式下面
			[root@db02 tmp]# mysqldump -S /tmp/mysql.sock -A -R --triggers --master-data=2 --single-transaction ... 
- Ubuntu 18.04  初始化(server版本 )
			系统安装 ubuntu 18.04 英文版,创建个人用户 初始系统 a.修改ip shell> vim /etc/network/interfaces auto ens33 iface ens3 ... 
- Zabbix 监控tomcat web
			个人博客:https://blog.sharedata.info/ 在zabbix监控web,web容器是tomcat 默认的端口是8080导致web监控失败!不能找到主机因此在修改tomcat 端口 ... 
- ASIHTTPRequest-Cookie的使用
			本文转载至 http://www.cocoachina.com/bbs/read.php?tid=93220&page=e&#a 持久化cookie ASIHTTPReques ... 
- Python菜鸟之路:Python基础(二)
			一.温故而知新 1. 变量命名方式 旧的方式: username = 'xxxx' password = 'oooo' 新的方式: username, password = 'xxxx', 'oooo ... 
