zoukankan      html  css  js  c++  java
  • 使用LINQ查询非泛型类型

    原文地址:http://www.cnblogs.com/buzz/archive/2009/04/23/1442159.html

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.IO;
    using System.Web.UI;
    using System.Web;
    using System.Threading;
    using System.Globalization;
    using System.Data;
    using System.Collections;

    namespace ConsoleApplication1
    {

        class Program
        {
            public class Cars
            {
                public string CarMake { get; set; }
                public string CarModel { get; set; }
                public int Year { get; set; }
            }
           
            public static void Main()
            {
                ArrayList carList = new ArrayList();
                carList.Add(new Cars
                {
                    CarMake = "BMW",
                    CarModel = "BMW Art",
                    Year = 1978
                });
                carList.Add(new Cars
                {
                    CarMake = "BMW",
                    CarModel = "Coupe",
                    Year = 1982
                });
                carList.Add(new Cars
                {
                    CarMake = "Renault",
                    CarModel = "Alpine",
                    Year = 1972
                });
                carList.Add(new Cars
                {
                    CarMake = "Porsche",
                    CarModel = "Maisto",
                    Year = 1976
                });


                var cc = from Cars car in carList
                         where car.CarMake == "BMW"
                         select car;

                var cc1 = from car in carList.Cast<Cars>()
                          where car.CarMake == "BMW"
                          select car;

                var cc2 = from car in carList.OfType<Cars>()
                          where car.CarMake == "BMW"
                          select car;


                foreach (Cars c in cc)
                {
                    Console.WriteLine(c.CarMake + "-" + c.CarModel);
                }

                Console.ReadLine();
            }
        }
    }     

  • 相关阅读:
    oracle分页查询sql写法
    查询一张表的id,不在另外一张表的某个字段的数据
    PowerDesigner 使用详解
    java JUC多线程高并发编程
    npm node-sass安装失败解决方法
    Vue中展示二级路由的默认模块 若依框架 自定义指令权限的使用说明
    vue 2.6以后slot 的变化使用
    java中 List<? extends T>与List<? super T> 表示的意思和区别
    java springboot自定义注解 和 时间加一天 一个月 一年方式
    js中||与&&的用法以及every()与some()的用法
  • 原文地址:https://www.cnblogs.com/niaowo/p/3911947.html
Copyright © 2011-2022 走看看