Get all reversed cars : Reverse « LINQ « C# / CSharp Tutorial






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

    class Car
    {
        public string PetName;
        public string Color;
        public int Speed;
        public string Make;
        
        public override string ToString()
        {
            return string.Format("Make={0}, Color={1}, Speed={2}, PetName={3}",Make, Color, Speed, PetName);
        }
    }
    class Program
    {
        static void Main(string[] args)
        {
            Car[] myCars = new []{
                new Car{ PetName = "A", Color = "Silver", Speed = 100, Make = "BMW"},
                new Car{ PetName = "B", Color = "Black", Speed = 55, Make = "VW"},
                new Car{ PetName = "C", Color = "White", Speed = 43, Make = "Ford"}
            };
        
            var subset = (from c in myCars select c).Reverse<Car>();
            foreach (Car c in subset)
            {
                Console.WriteLine(c.ToString());
            }
        
        }
    }








22.61.Reverse
22.61.1.Reverse does exactly as it says
22.61.2.An Example Calling the Reverse Operator
22.61.3.Get all reversed cars