Esempio n. 1
0
 static bool FindFords(ClassicCar car)
 {
     if (car.m_Make == "Ford")
     {
         return(true);
     }
     return(false);
 }
Esempio n. 2
0
        static void Main(string[] args)
        {
            List <ClassicCar> carList = new List <ClassicCar>();

            populateData(carList);

            //How many cars are there in the collection?
            Console.WriteLine("There are {0} cars in the entire collection.\n", carList.Count);

            //How many fords are there?
            List <ClassicCar> fordList = carList.FindAll(FindFords);

            Console.WriteLine("There are {0} Fords in the entire collection.\n", fordList.Count);

            //What is the most valuable car?
            ClassicCar mostValCar = null;
            int        highValue  = 0;

            foreach (ClassicCar c in carList)
            {
                if (c.m_Value > highValue)
                {
                    mostValCar = c;
                    highValue  = c.m_Value;
                }
            }
            Console.WriteLine("The most valuable car is a {0} {1} {2} at ${3}\n",
                              mostValCar.m_Year, mostValCar.m_Make, mostValCar.m_Model, mostValCar.m_Value);
            //What is the entire collection worth?
            int totalValue = 0;

            foreach (ClassicCar c in carList)
            {
                totalValue += c.m_Value;
            }
            Console.WriteLine("The entire collection is worth {0}\n", totalValue);
            //How many unique manufacturers are there?
            Dictionary <string, bool> makes = new Dictionary <string, bool>();

            foreach (ClassicCar c in carList)
            {
                try
                {
                    makes.Add(c.m_Make, true);
                }
                catch (Exception e) { }
            }
            ;
            Console.WriteLine("The collection contains {0} unique manufacturers.\n", makes.Keys.Count);

            Console.WriteLine("\nHit Enter key to continue...");
            Console.ReadLine();
        }