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);

最新文章

  1. SQL优化技术分析-4:其他
  2. 增加SWAP空间的方法
  3. NativeScript 也能开发桌面应用 (nativescript-dotnet-runtime)
  4. js-JavaScript高级程序设计学习笔记16
  5. 基于WDF的PCI/PCIe接口卡Windows驱动程序(4)- 驱动程序代码(源文件)
  6. 《JAVA与模式》之享元模式
  7. Android拼图游戏
  8. C语言中的宏展开
  9. 小学生玩ACM----优先队列
  10. [AngularJS - app] AngularJS Location-picker app
  11. 根据引用jar包路径查找原JAR包
  12. echarts仪表盘如何设置图例(legend)
  13. CMake 条件判断
  14. 网络1712--c语言第二次作业总结
  15. bzoj 3704 昊昊的机油之GRST - 贪心
  16. gcc 无法编译c17程序解决办法
  17. 大话前端解析Json对象
  18. Spring IOC 相关的面试题
  19. s3c2140 开发板笔记
  20. SQL优化系列——查询优化器

热门文章

  1. Hibernate学习之单向多对一映射
  2. Atitit.获取approot&#160;api&#160;应用根路径&#160;java&#160;c#.net&#160;php&#160;asp
  3. bean对应mapper.xml字段
  4. JFinal中Controller的应用
  5. Swift中文教程(七)--协议,扩展和泛型
  6. Swing实现系统托盘
  7. android 各版本的区别
  8. ios - 使用@try、catch捕获异常:
  9. EhCache 集群 配置(RMI方式)
  10. 九度OJ 1199:找位置 (计数)