zoukankan      html  css  js  c++  java
  • Linq操作ArrayList

    ArrayList实现了System.Collections空间下的IEnumerable接口,这个接口是非泛型的。如果要使用LINQ,必须声明枚举变量的类型,依赖Cast查询运算符转换枚举类型。

    using System;
    using System.Collections;
    using System.Collections.Generic;
    using System.Data;
    using System.IO;
    using System.Linq;
    
    namespace ConsoleApp4
    {
        class Program
        {
            static void Main(string[] args)
            {
                var arrayList = GetArrayList();
    
                //查询表达式
                var query = from Student student in arrayList
                            where student.Scores[0] > 95
                            select student;
    
                //方法调用
                var query2 = arrayList.Cast<Student>().Where(x => x.Scores[0] > 95);
            }
    
            static ArrayList GetArrayList()
            {
                ArrayList arrList = new ArrayList { new Student
                    {
                        FirstName = "Svetlana",
                        LastName = "Omelchenko",
                        Scores = new int[] { 98, 92, 81, 60 }
                    }, new Student
                    {
                        FirstName = "Claire",
                        LastName = "O’Donnell",
                        Scores = new int[] { 75, 84, 91, 39 }
                    }, new Student
                    {
                        FirstName = "Claire",
                        LastName = "O’Donnell",
                        Scores = new int[] { 75, 84, 91, 39 }
                    },new Student
                    {
                        FirstName = "Cesar",
                        LastName = "Garcia",
                        Scores = new int[] { 97, 89, 85, 82 }
                    }};
    
                return arrList;
            }
        }
    
        public class Student
        {
            public string FirstName { get; set; }
            public string LastName { get; set; }
            public int[] Scores { get; set; }
        }
    }

     

  • 相关阅读:
    2020.4.21 考试T1 HDU 5729
    BZOJ 4198: [Noi2015]荷马史诗
    BZOJ 1052: [HAOI2007]覆盖问题
    BZOJ 1087: [SCOI2005]互不侵犯King
    BZOJ 4466 线性函数
    Linux如何挂载U盘
    集中式日志分析平台
    ELK5.2+kafka+zookeeper+filebeat集群部署
    浅析ES的_source、_all、store、index
    IndexOf、LastIndexOf、Substring的用法
  • 原文地址:https://www.cnblogs.com/colorchild/p/12708146.html
Copyright © 2011-2022 走看看