Exemple #1
0
        static void Main(string[] args)
        {
            // create two new custom collections for Cars and Students
            CustomCollectionList <Car>     myCarList     = new CustomCollectionList <Car>();
            CustomCollectionList <Student> myStudentList = new CustomCollectionList <Student>();

            // fill cars collection, printout a whole collection
            int carObjectCount = FillCollectionWithCars(myCarList);

            Console.WriteLine($"Several cars were created, cars count is {carObjectCount}");
            PrintCustomCollection(myCarList);
            Console.WriteLine(new string('=', 20));

            // Find all cars with speed more than 100 and sort them by name (using reflection)
            // i don't like hardcode, need to investigate how can solve it better
            Console.WriteLine("Find all cars with speed more than 100 and sort them by name (using reflection)");
            string searchStr = "Model";

            foreach (var curCar in myCarList.FindItems(((x) => x.MaxSpeed > 100), searchStr))
            {
                Console.WriteLine(curCar.ToString());
            }
            Console.WriteLine(new string('=', 20));

            // find two cars with highest speed among cars with speed more than 100
            foreach (var curCar in myCarList.FindItems(((x) => x.MaxSpeed > 100), ((x) => x.MaxSpeed), 2))
            {
                Console.WriteLine(curCar.ToString());
            }
            Console.WriteLine(new string('=', 20));

            // remove item by ID (check realization, pls, im not sure that it is right
            string idToDelete = "Car_0002";

            if (myCarList.RemoveByID(idToDelete))
            {
                Console.WriteLine($"Item with id={idToDelete}");
                PrintCustomCollection(myCarList);
            }

            int studentObjectCount = FillCollectionWithStudents(myStudentList);

            Console.ReadKey();
        }