Linq Over ArrayList : foreach loop « LINQ « C# / CSharp Tutorial






using System;
using System.Collections.Generic;
using System.Text;
using System.Xml.Linq;
using System.Linq;

using System.Collections;

    class Car
    {
        public string PetName;
        public string Color;
        public int Speed;
        public string Make;
    }

    class Program
    {
        static void Main(string[] args)
        {
            ArrayList myCars = new ArrayList();  
            myCars.Add(new Car{ PetName = "Henry", Color = "Silver", Speed = 100, Make = "BMW"});
            myCars.Add(new Car{ PetName = "Clunker", Color = "Rust", Speed = 5, Make = "Yugo"});
            myCars.Add(new Car { PetName = "Melvin", Color = "White", Speed = 43, Make = "Ford" });

            IEnumerable<Car> myCarsEnum = myCars.OfType<Car>();
            // Create a query expression. 
            var fastCars = from c in myCarsEnum where c.Speed > 55 select c;

            foreach (var car in fastCars)
            {
                Console.WriteLine("{0} is going too fast!", car.PetName);
            }
        }
    }








22.14.foreach loop
22.14.1.Use foreach loop to deal with the result from linq
22.14.2.Linq Over Array Using Sequence
22.14.3.Linq Over ArrayList
22.14.4.Linq To Objects
22.14.5.Linq over array
22.14.6.Cars going faster than 55, ordered by PetName
22.14.7.Simple linq