原文地址: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();
}
}
}