首页 > 其他 > 详细

LINQ 学习路程 -- 查询操作 OfType

时间:2017-03-22 22:52:52      阅读:154      评论:0      收藏:0      [点我收藏+]

OfType操作根据集合中的元素是否是给定的类型进行筛选

IList mixedList = new ArrayList();
mixedList.Add(0);
mixedList.Add("One");
mixedList.Add("Two");
mixedList.Add(3);
mixedList.Add(new Student() { StudentID = 1, StudentName = "Bill" });

var stringResult = from s in mixedList.OfType<string>()
                   select s;

var intResult = from s in mixedList.OfType<int>()
                select s;
var stringResult = mixedList.OfType<string>();

 

LINQ 学习路程 -- 查询操作 OfType

原文:http://www.cnblogs.com/lanpingwang/p/6602145.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!