• 使用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();
            }
        }
    }     

  • 相关阅读:
    Python之从头开始建立项目流程
    Python之建立APP流程以及SVN 的使用
    python之继承
    Python之实例对象的增删改查
    Python之类属性的增删改查
    read big file
    python minus 3 days or n days
    movie
    pyqt convert ui file to py file
    pyqt4 borderless window
  • 原文地址:https://www.cnblogs.com/niaowo/p/3911947.html
Copyright © 2020-2023  润新知