LINQ 学习路程 -- 查询操作 OfType
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>();