コード例 #1
0
ファイル: Program.cs プロジェクト: ChegnduJackli/Projects
        static void Main()
        {
            var dealer = new CarDealer();

            var michael = new Consumer("Michael");
            dealer.NewCarInfo += michael.NewCarIsHere;

            dealer.NewCar("Mercedes");

            var nick = new Consumer("Nick");
            dealer.NewCarInfo += nick.NewCarIsHere;

            dealer.NewCar("Ferrari");

            dealer.NewCarInfo -= michael.NewCarIsHere;

            dealer.NewCar("Toyota");
        }
コード例 #2
0
ファイル: Program.cs プロジェクト: Ricky-Hao/ProCSharp
        static void Main()
        {
            var dealer = new CarDealer();

              var michael = new Consumer("Michael");
              WeakCarInfoEventManager.AddListener(dealer, michael);

              dealer.NewCar("Mercedes");

              var sebastian = new Consumer("Sebastian");
              WeakCarInfoEventManager.AddListener(dealer, sebastian);

              dealer.NewCar("Ferrari");

              WeakCarInfoEventManager.RemoveListener(dealer, michael);

              dealer.NewCar("Red Bull Racing");
        }
コード例 #3
0
ファイル: Program.cs プロジェクト: ChegnduJackli/Projects
        static void Main()
        {
            var dealer = new CarDealer();

            var michael = new Consumer("Michael");
            WeakCarInfoEventManager.AddListener(dealer, michael);

            dealer.NewCar("Mercedes");

            var nick = new Consumer("Nick");
            WeakCarInfoEventManager.AddListener(dealer, nick);

            dealer.NewCar("Ferrari");

            WeakCarInfoEventManager.RemoveListener(dealer, michael);

            dealer.NewCar("Toyota");
        }
コード例 #4
0
    static void Main()
    {
      var dealer = new CarDealer();

      var daniel = new Consumer("Daniel");
      dealer.NewCarInfo += daniel.NewCarIsHere;

      dealer.NewCar("Mercedes");

      var sebastian = new Consumer("Sebastian");
      dealer.NewCarInfo += sebastian.NewCarIsHere;

      dealer.NewCar("Ferrari");

      dealer.NewCarInfo -= sebastian.NewCarIsHere;


      dealer.NewCar("Red Bull Racing");
    }
コード例 #5
0
        static void Main07()
        {
            var dealer = new CarDealer();

            var micheal = new Consumer("Micheal");

            WeakCarInfoEventManager.AddListener(dealer, micheal);

            dealer.NewCar("Mercedes");

            var nick = new Consumer("Nick");

            WeakCarInfoEventManager.AddListener(dealer, nick);

            dealer.NewCar("Ferrari");

            WeakCarInfoEventManager.RemoveListener(dealer, micheal);

            dealer.NewCar("Toyota");
        }
コード例 #6
0
        private void AddCarDealerButton_Click(object sender, EventArgs e)
        {
            bool isDataCorrect = validateService.validateValuesForElement(
                CarDealerBeautyTB, CarDealerOldTB, CarDealerName);

            if (isDataCorrect)
            {
                float beuty = float.Parse(CarDealerBeautyTB.Text);
                float old   = float.Parse(CarDealerOldTB.Text);
                updateMaxPointValue(beuty);
                updateMaxPointValue(old);
                String    name      = CarDealerName.Text;
                CarDealer carDealer = new CarDealer(old, beuty, name);
                carDealers.Add(carDealer);
                CarDealerListBox.Items.Add(carDealer.toString());
            }
            else
            {
                MessageBox.Show("Nieprawidłowe wartości dla komisu.");
            }
        }
コード例 #7
0
        static void Main()
        {
            var dealer = new CarDealer();

            var daniel = new Consumer("Daniel");

            dealer.NewCarInfo += daniel.NewCarIsHere;

            dealer.NewCar("Mercedes");

            var sebastian = new Consumer("Sebastian");

            dealer.NewCarInfo += sebastian.NewCarIsHere;

            dealer.NewCar("Ferrari");

            dealer.NewCarInfo -= sebastian.NewCarIsHere;


            dealer.NewCar("Red Bull Racing");
        }
コード例 #8
0
        static void Main()
        {
            var dealer = new CarDealer();

            var micheal = new Consumer("micheal");

            dealer.NewCarInfo += micheal.NewcarIsHere;
            dealer.NewCar("Ferrari");

            //var sebastian = new Consumer("sebastian");
            //dealer.NewCarInfo += sebastian.NewcarIsHere;
            //dealer.NewCar("Mercedes");
            //dealer.NewCarInfo += sebastian.NewcarIsHere;

            //dealer.NewCarInfo -= micheal.NewcarIsHere;
            //dealer.NewCar("Red Bull Racing");

            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new Form1());
        }
コード例 #9
0
ファイル: Program.cs プロジェクト: Arovelti/It-Academy
        static void Main(string[] args)
        {
            Motorcycle aboutFord = new Motorcycle();

            Console.WriteLine("About car: ");
            aboutFord.aboutCar();


            CarDealer dealerFord = new CarDealer();

            Console.WriteLine("Dealer info: ");
            dealerFord.aboutCar();

            CarClient clientFord = new CarClient();

            Console.WriteLine("Client: ");
            clientFord.aboutCar();
            clientFord.GetColor("Red");
            clientFord.GetYear(2019);
            clientFord.carModel = "Mondeo";
            Console.ReadKey();
        }
コード例 #10
0
        public void NewCarEventListener(object sender, NewCarEventArgs args)
        {
            CarDealer unDealer = (CarDealer)sender;

            System.Console.WriteLine("{0} dice: Parece que {1} me avisa que hay un nuevo {2}", this.Name, unDealer.Name, args.CarName);
        }
コード例 #11
0
 public void Execute(CarDealer dealer)
 {
     Console.WriteLine("Number of all available Vehicles: " + dealer.TotalVehiclesAvailable);
 }
コード例 #12
0
 public void Execute(CarDealer dealer)
 {
     Execute(dealer.AllAvailableVehicles);
 }
コード例 #13
0
 public AddVehicleCommand(CarDealer carDealer)
 {
     this.carDealer = carDealer;
 }
コード例 #14
0
ファイル: Program.cs プロジェクト: kristina-s/CSharp-Advanced
        static void Main(string[] args)
        {
            #region List of cars and dealers
            List <Car> bmwCars = new List <Car>
            {
                new BMW("530", 5, "Diesel", 12.5, 55000, TypeOfCar.passenger, true),
                new BMW("X3", 5, "Petrol", 10.5, 33000, TypeOfCar.passenger, false),
                new BMW("X5 CV", 5, "Petrol", 14, 48000, TypeOfCar.cargo, false),
                new BMW("M4", 3, "Petrol", 11.5, 52000, TypeOfCar.passenger, true)
            };
            List <Car> audiCars = new List <Car>
            {
                new Audi("A3", 3, "Diesel", 7.5, 27000, TypeOfCar.passenger, "Dark Blue"),
                new Audi("A4", 5, "Diesel", 8, 34000, TypeOfCar.passenger, "Red"),
                new Audi("A7", 5, "Petrol", 8.5, 52000, TypeOfCar.passenger, "White"),
                new Audi("Q5", 5, "Diesel", 11, 55000, TypeOfCar.cargo, "Silver"),
                new Audi("Q7", 5, "Petrol", 13.5, 71000, TypeOfCar.cargo, "Matte Black")
            };
            List <Car> opelCars = new List <Car>
            {
                new Opel("Astra", 5, "Petrol", 7.5, 18000, TypeOfCar.passenger, "Germany"),
                new Opel("Antara", 5, "Diesel", 10, 22000, TypeOfCar.cargo, "USA"),
                new Opel("Corsa", 3, "Diesel", 6.5, 11000, TypeOfCar.passenger, "Hungary"),
                new Opel("Combo Cargo", 5, "Petrol", 9.5, 19000, TypeOfCar.cargo, "Germany"),
                new Opel("Insignia", 5, "Diesel", 8.5, 17000, TypeOfCar.passenger, "USA")
            };
            #endregion


            Console.WriteLine("Choose to enter one of the following car dealers");
            while (true)
            {
                Console.WriteLine("Press 1 for BMW, 2 for Audi, 3 for Opel...");
                try
                {
                    int userChoiceDealer = int.Parse(Console.ReadLine());

                    switch (userChoiceDealer)
                    {
                    //BMW Dealers
                    case 1:
                        CarDealer bmwDealer = new CarDealer();
                        bmwDealer.Name     = "BMW Dealership";
                        bmwDealer.Address  = "St. John's st 1A";
                        bmwDealer.CarsList = bmwCars;
                        Console.WriteLine("Welcome to BMW car dealership!");
                        Console.WriteLine("What kind of car would you like to buy?");
                        Console.WriteLine("Press 1 to see passenger vehicles");
                        Console.WriteLine("Press 2 to see cargo vehicles");
                        try
                        {
                            int userChoice = int.Parse(Console.ReadLine());
                            if (userChoice == 1)
                            {
                                List <Car> bmwPassenger = bmwDealer.CarsList
                                                          .Where(x => x.CarType == TypeOfCar.passenger)
                                                          .ToList();
                                foreach (var car in bmwPassenger)
                                {
                                    Console.WriteLine(car.CarInfo());
                                    Console.WriteLine($"Price in EUR: {car.PrintPrice("eur")}/ Price in MKD {car.PrintPrice("mkd")}");
                                }
                            }
                            else if (userChoice == 2)
                            {
                                List <Car> bmwCargo = bmwDealer.CarsList
                                                      .Where(x => x.CarType == TypeOfCar.cargo)
                                                      .ToList();
                                foreach (var car in bmwCargo)
                                {
                                    Console.WriteLine(car.CarInfo());
                                    Console.WriteLine($"Price in EUR: {car.PrintPrice("eur")}/ Price in MKD {car.PrintPrice("mkd")}");
                                }
                            }
                            else if ((userChoice != 1) || (userChoice != 2))
                            {
                                Console.WriteLine("No such option!");
                                break;
                            }
                            Console.WriteLine("--------------------------");
                            Console.WriteLine("You can enter minimum and maximum price range too see vehicles.");
                            Console.WriteLine("Press 1 to see prices in EUR, or 2 to see price in MKD denars");
                            try
                            {
                                int inpCurrency = int.Parse(Console.ReadLine());
                                if (inpCurrency == 1)
                                {
                                    Console.WriteLine("These prices are in euros! \n");
                                    GetMinAndMaxAndPrint(bmwDealer);
                                    continue;
                                }
                                else if (inpCurrency == 2)
                                {
                                    Console.WriteLine("These prices are in denars! \n");
                                    GetMinAndMaxAndPrintMKD(bmwDealer);
                                    continue;
                                }
                                else if ((inpCurrency != 1) || (inpCurrency != 2))
                                {
                                    Console.WriteLine("No such option!");
                                    continue;
                                }
                            }
                            catch (FormatException ex)
                            {
                                Console.WriteLine(ex.Message);
                            }
                            catch (Exception ex)
                            {
                                Console.WriteLine(ex.Message);
                            };
                        }
                        catch (FormatException ex)
                        {
                            Console.WriteLine(ex.Message);
                        }
                        catch (Exception ex)
                        {
                            Console.WriteLine(ex.Message);
                        };
                        break;

                    // AUDI dealership
                    case 2:
                        CarDealer audiDealer = new CarDealer();
                        audiDealer.Name     = "AUDI Dealership";
                        audiDealer.Address  = "55 Mill Road";
                        audiDealer.CarsList = audiCars;
                        Console.WriteLine("Welcome to AUDI car dealership!");
                        Console.WriteLine("What kind of car would you like to buy?");
                        Console.WriteLine("Press 1 to see passenger vehicles");
                        Console.WriteLine("Press 2 to see cargo vehicles");
                        try
                        {
                            int userChoice02 = int.Parse(Console.ReadLine());
                            if (userChoice02 == 1)
                            {
                                List <Car> audiPassenger = audiDealer.CarsList
                                                           .Where(x => x.CarType == TypeOfCar.passenger)
                                                           .ToList();
                                foreach (var car in audiPassenger)
                                {
                                    Console.WriteLine(car.CarInfo());
                                    Console.WriteLine($"Price in EUR: {car.PrintPrice("eur")}/ Price in MKD {car.PrintPrice("mkd")}");
                                }
                            }
                            else if (userChoice02 == 2)
                            {
                                List <Car> audiCargo = audiDealer.CarsList
                                                       .Where(x => x.CarType == TypeOfCar.cargo)
                                                       .ToList();
                                foreach (var car in audiCargo)
                                {
                                    Console.WriteLine(car.CarInfo());
                                    Console.WriteLine($"Price in EUR: {car.PrintPrice("eur")}/ Price in MKD {car.PrintPrice("mkd")}");
                                }
                            }
                            else if ((userChoice02 != 1) || (userChoice02 != 2))
                            {
                                Console.WriteLine("No such option!");
                                break;
                            }
                            Console.WriteLine("--------------------------");
                            Console.WriteLine("You can enter minimum and maximum price range too see vehicles.");
                            Console.WriteLine("Press 1 to see prices in EUR, or 2 to see price in MKD denars");
                            try
                            {
                                int inpCurrency = int.Parse(Console.ReadLine());
                                if (inpCurrency == 1)
                                {
                                    Console.WriteLine("These prices are in euros! \n");
                                    GetMinAndMaxAndPrint(audiDealer);
                                    continue;
                                }
                                else if (inpCurrency == 2)
                                {
                                    Console.WriteLine("These prices are in denars! \n");
                                    GetMinAndMaxAndPrintMKD(audiDealer);
                                    continue;
                                }
                                else if ((inpCurrency != 1) || (inpCurrency != 2))
                                {
                                    Console.WriteLine("No such option!");
                                    break;
                                }
                            }
                            catch (FormatException ex)
                            {
                                Console.WriteLine(ex.Message);
                            }
                            catch (Exception ex)
                            {
                                Console.WriteLine(ex.Message);
                            };
                        }
                        catch (FormatException ex)
                        {
                            Console.WriteLine(ex.Message);
                        }
                        catch (Exception ex)
                        {
                            Console.WriteLine(ex.Message);
                        };
                        break;

                    //OPEL Dealership
                    case 3:
                        CarDealer opelDealer = new CarDealer();
                        opelDealer.Name     = "OPEL Dealership";
                        opelDealer.Address  = "100 Downtown St.";
                        opelDealer.CarsList = opelCars;
                        Console.WriteLine("Welcome to OPEL car dealership!");
                        Console.WriteLine("What kind of car would you like to buy?");
                        Console.WriteLine("Press 1 to see passenger vehicles");
                        Console.WriteLine("Press 2 to see cargo vehicles");
                        try
                        {
                            int userChoice03 = int.Parse(Console.ReadLine());
                            if (userChoice03 == 1)
                            {
                                List <Car> opelPassenger = opelDealer.CarsList
                                                           .Where(x => x.CarType == TypeOfCar.passenger)
                                                           .ToList();
                                foreach (var car in opelPassenger)
                                {
                                    Console.WriteLine(car.CarInfo());
                                    Console.WriteLine($"Price in EUR: {car.PrintPrice("eur")}/ Price in MKD {car.PrintPrice("mkd")}");
                                }
                            }
                            else if (userChoice03 == 2)
                            {
                                List <Car> opelCargo = opelDealer.CarsList
                                                       .Where(x => x.CarType == TypeOfCar.cargo)
                                                       .ToList();
                                foreach (var car in opelCargo)
                                {
                                    Console.WriteLine(car.CarInfo());
                                    Console.WriteLine($"Price in EUR: {car.PrintPrice("eur")}/ Price in MKD {car.PrintPrice("mkd")}");
                                }
                            }
                            else if ((userChoice03 != 1) || (userChoice03 != 2))
                            {
                                Console.WriteLine("No such option!");
                            }
                            Console.WriteLine("--------------------------");
                            Console.WriteLine("You can enter minimum and maximum price range too see vehicles.");
                            Console.WriteLine("Press 1 to see prices in EUR, or 2 to see price in MKD denars");
                            try
                            {
                                int inpCurrency = int.Parse(Console.ReadLine());
                                if (inpCurrency == 1)
                                {
                                    Console.WriteLine("These prices are in euros! \n");
                                    GetMinAndMaxAndPrint(opelDealer);
                                    continue;
                                }
                                else if (inpCurrency == 2)
                                {
                                    Console.WriteLine("These prices are in denars! \n");
                                    GetMinAndMaxAndPrintMKD(opelDealer);
                                    continue;
                                }
                                else if ((inpCurrency != 1) || (inpCurrency != 2))
                                {
                                    Console.WriteLine("No such option!");
                                    continue;
                                }
                            }
                            catch (FormatException ex)
                            {
                                Console.WriteLine(ex.Message);
                            }
                            catch (Exception ex)
                            {
                                Console.WriteLine(ex.Message);
                            };
                        }
                        catch (FormatException ex)
                        {
                            Console.WriteLine(ex.Message);
                        }
                        catch (Exception ex)
                        {
                            Console.WriteLine(ex.Message);
                        };
                        break;

                    default:
                        Console.WriteLine("No such option! Try again!");
                        break;
                    }
                    continue;
                }
                catch (FormatException ex)
                {
                    Console.WriteLine(ex.Message);
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                }
            }
        }
コード例 #15
0
ファイル: Program.cs プロジェクト: dearz/Practice
        // 弱事件示例
        private static void WeakEvent()
        {
            var dealer = new CarDealer();
            var michael = new Consumer("Michael");

            WeakCarInfoEventManager.AddListener(dealer, michael);

            dealer.NewCar("Mercedes");

            Console.ReadKey();
        }
コード例 #16
0
 public string CountAll()
 {
     return(CarDealer.GetInstance().Cars.Count.ToString());
 }
コード例 #17
0
ファイル: Program.cs プロジェクト: striveCj/StudyCode
        static void Main(string[] args)
        {
            //int x = 40;
            //GetAString firstStringMethod=new GetAString(x.ToString);
            //Console.WriteLine($"String is {firstStringMethod}");

            //int x = 40;
            //GetAString firstStringMethod = x.ToString;
            //Console.WriteLine($"{firstStringMethod}");
            //var balance=new Currency(34,50);
            //firstStringMethod = balance.ToString;
            //Console.WriteLine($"{firstStringMethod}");
            //firstStringMethod=new GetAString(Currency.GetCurrencyUnit);
            //Console.WriteLine($"{firstStringMethod}");

            //DoubleOp[] operations =
            //{
            //    MathOperations.MultiplyByTwo,
            //    MathOperations.Square
            //};
            //for (int i = 0; i < operations.Length; i++)
            //{
            //    Console.WriteLine($"Using operations[{i}]");
            //    ProcessAndDisplayNumber(operations[i], 2.0);
            //    ProcessAndDisplayNumber(operations[i], 7.94);
            //    ProcessAndDisplayNumber(operations[i],1.414);
            //    Console.WriteLine();
            //}

            //Employee[] employees =
            //{
            //    new Employee("a", 20000),
            //    new Employee("b",20000),
            //    new Employee("c",20000),
            //    new Employee("d",20000),
            //    new Employee("e",20000),
            //};
            //BubbleSorter.Sort(employees,Employee.CompareSalary);
            //foreach (var employee in employees)       {
            //    Console.WriteLine(employee);
            //}
            //Action<double> operation = MathOperations.MultiplyByTwo;
            //operation += MathOperations.Square;
            //ProcessAndDisplayNumber(operation,2.0);
            //ProcessAndDisplayNumber(operation, 7.94);
            //ProcessAndDisplayNumber(operation, 1.414);
            //Console.WriteLine(1);
            Action d1 = One;

            d1 += Two;
            try
            {
                d1();
            }
            catch (Exception e)
            {
                Console.WriteLine("Exception caught1");
            }

            string mid = ",middle part,";
            Func <string, string> lambda = param =>
            {
                param += mid;
                param += " amd this was added to the string";
                return(param);
            };

            Console.WriteLine(lambda("Start of string"));

            var dealer   = new CarDealer();
            var valtteri = new Consumer("Valtteri");

            dealer.NewCarInfo += valtteri.NewCarIsHere;
            dealer.NewCar("Williams");

            var max = new Consumer("Max");

            dealer.NewCarInfo += max.NewCarIsHere;
            dealer.NewCar("Mercedes");
            dealer.NewCarInfo -= valtteri.NewCarIsHere;
            dealer.NewCar("Ferrari");
        }
コード例 #18
0
 public string CountTypes()
 {
     return(CarDealer.GetInstance().Cars.Select(x => x.Manufacturer).Distinct().Count().ToString());
 }
コード例 #19
0
 public InMemoryDB()
 {
     Dealer = new CarDealer();
 }
コード例 #20
0
        static void Main(string[] args)
        {
            int        x = 40;
            GetAString firstStringMethod = x.ToString;

            Console.WriteLine($"String is {firstStringMethod()}");
            var balance = new Currency(34, 50);

            firstStringMethod = balance.ToString;
            Console.WriteLine($"String is {firstStringMethod()}");

            firstStringMethod = new GetAString(Currency.GetCurrencyUnit);
            Console.WriteLine($"String is {firstStringMethod()}");
            Console.WriteLine($"------------------");
            DoubleOp[] operations =
            {
                MathOperations.MultiplayByTwo,
                MathOperations.Square
            };
            //声明参数类型是double,返回类型是double的Func委托,
            //对于Func<a,b>, b类型是返回类型,a类型是输入参数类型,输入参数类型可以有多个
            //例如Func<a,a,c,b>,表示3个参数,分别是a类型,a类型,c类型,返回值是b类型
            Func <double, double>[] funcOperations =
            {
                MathOperations.MultiplayByTwo,
                MathOperations.Square
            };
            for (int i = 0; i < operations.Length; i++)
            {
                Console.WriteLine($"Using operation[{i}]");
                ProcessAndDisplayNumber(operations[i], 2.0);
                ProcessAndDisplayNumber(operations[i], 7.94);
                ProcessAndDisplayNumber(operations[i], 1.414);
            }

            for (int i = 0; i < funcOperations.Length; i++)
            {
                Console.WriteLine($"Using operation[{i}]");
                ProcessFuncAndDisplayNumber(funcOperations[i], 2.0);
                ProcessFuncAndDisplayNumber(funcOperations[i], 7.94);
                ProcessFuncAndDisplayNumber(funcOperations[i], 1.414);
            }

            Console.WriteLine($"------------------");

            Employee[] employees =
            {
                new Employee("Tom",       20000),
                new Employee("Jack",      10000),
                new Employee("Bob",       15000),
                new Employee("Roy",  100000.38m),
                new Employee("Lily",      23000),
                new Employee("Jean",      50000),
            };
            //将Employee.CompareSalary方法作为委托参数传入BubbleSorter.Sort方法
            BubbleSorter.Sort(employees, Employee.CompareSalary);
            foreach (var item in employees)
            {
                Console.WriteLine(item);
            }

            Console.WriteLine($"------------------");

            //多播委托,一个委托可以包含多个方法,但是委托签名必须返回void,否则只能得到委托调用最后一个方法的结果
            Action <double> actionOperations = MathOperations.ActionMultiplayByTwo;

            actionOperations += MathOperations.ActionSquare;
            ProcesActionAndDisplayNumber(actionOperations, 2.0);
            ProcesActionAndDisplayNumber(actionOperations, 7.94);
            ProcesActionAndDisplayNumber(actionOperations, 1.414);
            Console.WriteLine($"------------------");

            string mid = ", middle part,";
            //匿名方法
            //   Func<string, string> anonDel = delegate(string param)
            //   {
            //       param += mid;
            //       param += " and this was added to the string";
            //       return param;
            //};
            //使用lambda表达式的匿名方法,参数的类型和委托定义的类型对照
            Func <string, string> anonDel = param =>
            {
                param += mid;
                param += " and this was added to the string";
                return(param);
            };

            Console.WriteLine(anonDel("Start of string"));

            Console.WriteLine($"------------------");

            var dealer   = new CarDealer();
            var valtteri = new Consumer("Valtteri");

            dealer.NewCarInfo += valtteri.NewCarIsHere;
            dealer.NewCar("Williams");

            var max = new Consumer("Max");

            dealer.NewCarInfo += max.NewCarIsHere;
            dealer.NewCar("Mercedes");
            dealer.NewCarInfo -= valtteri.NewCarIsHere;
            dealer.NewCar("Ferrari");
        }
コード例 #21
0
ファイル: Program.cs プロジェクト: engimaxp/LearningDelegates
        static void Main(string[] args)
        {

            var dealer = new CarDealer();

            var michael = new Consumer("Michael");



            //dealer.NewCarInfo += michael.NewCarIsHere;

            //dealer.NewCar("Ferrari");

            //var sebastian = new Consumer("sebastian");
            //dealer.NewCarInfo += sebastian.NewCarIsHere;

            //dealer.NewCar("Mercedes");

            //dealer.NewCarInfo -= michael.NewCarIsHere;

            //dealer.NewCar("Red Bull");

            //int x = 40;
            //GetAString firstStringMethod = new GetAString(x.ToString);
            //Console.WriteLine("String is {0}",firstStringMethod());
            //Console.ReadLine();

            //Currency balance = new Currency(34, 50);
            //firstStringMethod = balance.ToString;
            //Console.WriteLine("string is {0}",firstStringMethod());

            //firstStringMethod = new GetAString(Currency.GetCurrencyUnit);
            //Console.WriteLine("string is {0}", firstStringMethod()); 
            //Action<double> ops1 = MathOp.Cheng2;
            //Action<double> ops2 = MathOp.Square;
            //Action<double> ops3 = ops1 + ops2;
            //Action<double> ops4 = param =>
            //{
            //    Console.WriteLine("Value is {0},result of operation is {1}",param,param+33);
            //};
            //ops1(7.94);
            //ops2(7.94);
            //ops3(7.94);
            //ops4(7.94);
                //Console.WriteLine("Value is {0},result of operation is {1}", 2.0, ops[i](2.0));
                //Console.WriteLine("Value is {0},result of operation is {1}", 7.94, ops[i](7.94));
                //Console.WriteLine("Value is {0},result of operation is {1}", 1.414, ops[i](1.414));



            //var values = new List<int>() { 10, 20, 30 };
            //var funcs = new List<Func<int>>();
            //foreach (var val in values)
            //{
            //    funcs.Add(() => val);
            //}
            //foreach (var f in funcs)
            //{
            //    Console.WriteLine(f());
            //}





                Console.ReadLine();

        }
コード例 #22
0
        public void Execute(CarDealer dealer)
        {
            var vehicleTypes = Assembly.GetExecutingAssembly().GetTypes().Where(t => t.BaseType == typeof(Vehicle))
                               .ToArray();

            Vehicle v;
            IEnumerable <PropertyInfo> vehicleProperties;

            while (true)
            {
                Console.Write("Select vehicle kind(");
                for (int i = 0; i < vehicleTypes.Length; ++i)
                {
                    Console.Write($"{i.ToString()} {vehicleTypes[i].Name}");
                    if (i < vehicleTypes.Length - 1)
                    {
                        Console.Write(", ");
                    }
                }

                Console.Write("): ");
                string input = Console.ReadLine();
                int    index;

                if (!int.TryParse(input, out index))
                {
                    continue;
                }
                if (index < 0 || index >= vehicleTypes.Length)
                {
                    continue;
                }

                v = (Vehicle)Activator.CreateInstance(vehicleTypes[index]);
                vehicleProperties = vehicleTypes[index].GetProperties()
                                    .Where(x => Attribute.IsDefined(x, typeof(VehicleProperty)));

                break;
            }

            foreach (var vehicleProperty in vehicleProperties)
            {
                while (true)
                {
                    Console.Write($"Please enter {vehicleProperty.Name}: ");
                    string input = Console.ReadLine();
                    if (vehicleProperty.PropertyType.Equals(typeof(string)))
                    {
                        vehicleProperty.SetValue(v, input);
                        break;
                    }
                    else
                    {
                        try
                        {
                            vehicleProperty.SetValue(v, parseToPrimitiveType(input, vehicleProperty.PropertyType));
                            break;
                        }
                        catch (FormatException e)
                        {
                        }
                    }
                }
            }

            /*while (true)
             * {
             *  Console.Write("Enter price: ");
             *  string input = Console.ReadLine();
             *  double price;
             *
             *  if (!double.TryParse(input, out price)) continue;
             *  v.Price = price;
             *  break;
             * }
             *
             * Console.Write("Enter license plate: ");
             * v.LicensePlate = Console.ReadLine();
             * Console.Write("Enter vendor: ");
             * v.Vendor = Console.ReadLine();*/

            dealer.AddVehicle(v);
        }
コード例 #23
0
 public void Execute(CarDealer dealer)
 {
     Console.WriteLine("Total value of all vehicles available: " + dealer.TotalValueOfAllVehicles);
 }
コード例 #24
0
        public void findTwoBoundaryPoints(CarDealer carDealer, List <Point> points)
        {
            sortedPoints = ppService.sortPoints(points);
            List <Point> boundaryPointsForOne = new List <Point>();

            Debug.WriteLine("Posortowane punkty.");
            foreach (Point point in sortedPoints)
            {
                Debug.WriteLine(point.toString() + ", isUP: " + point.isUp + ", position: " + point.position);
            }

            DirectionCorrection directionCorrection = new DirectionCorrection();

            Point firstPoint  = null;
            Point secondPoint = null;

            List <List <Point> > candiatesPoints = new List <List <Point> >();

            Debug.WriteLine("Ilość posortowanych punktów przed forami: " + sortedPoints.Count);
            for (int i = 0; i < sortedPoints.Count - 1; i++)
            {
                if (sortedPoints[i].isUp != directionCorrection.firstPointFlow[sortedPoints[i].position.ToString()])
                {
                    continue;
                }

                firstPoint = sortedPoints[i];
                Debug.WriteLine("Pierwszy punkt przynany jako: " + sortedPoints[i].toString());

                for (int j = i + 1; j < sortedPoints.Count; j++)
                {
                    String key = sortedPoints[i].position.ToString() + "" + sortedPoints[j].position.ToString();

                    Debug.WriteLine("Ilość posortowanych punktów: " + sortedPoints.Count);
                    Debug.WriteLine("Indexy: {0}, {1}", i, j);
                    Debug.WriteLine("Key: " + key);

                    if (sortedPoints[j].isUp != directionCorrection.secondPointFlow[key])
                    {
                        continue;
                    }

                    Debug.WriteLine("Drugi punkt przynany jako: " + sortedPoints[j].toString());
                    secondPoint = sortedPoints[j];
                    break;
                }

                if (firstPoint != null && secondPoint != null)
                {
                    List <Point> twoPoints = new List <Point>();
                    twoPoints.Add(firstPoint);
                    twoPoints.Add(secondPoint);
                    candiatesPoints.Add(twoPoints);
                }

                secondPoint = null;
            }

            if (candiatesPoints.Count == 0)
            {
                Debug.WriteLine("Nie odnaleziono żadnych punktów.");

                bool isUpLastPoint     = sortedPoints[sortedPoints.Count - 1].isUp;
                int  lastPointPosition = sortedPoints[sortedPoints.Count - 1].position;

                if (directionCorrection.firstPointFlow[lastPointPosition.ToString()] == isUpLastPoint)
                {
                    bool isUpFirstPoint     = sortedPoints[0].isUp;
                    int  firstPointPosition = sortedPoints[0].position;

                    String position = lastPointPosition.ToString() + "" + firstPointPosition.ToString();
                    if (directionCorrection.secondPointInvertedFlow[position] == isUpFirstPoint)
                    {
                        Debug.WriteLine("Pierwszy punkt: " + sortedPoints[0].toString());
                        Debug.WriteLine("Drugi punkt: " + sortedPoints[sortedPoints.Count - 1].toString());
                        boundaryPointsForOne.Add(sortedPoints[0]);
                        boundaryPointsForOne.Add(sortedPoints[sortedPoints.Count - 1]);
                        boundaryPoints.Add(boundaryPointsForOne);
                    }
                }
            }
            else
            {
                Debug.WriteLine("Ilość kandydatów: " + candiatesPoints.Count);


                foreach (List <Point> listOfPoints in candiatesPoints)
                {
                    Debug.WriteLine("Kandydat");
                    foreach (Point point in listOfPoints)
                    {
                        Debug.WriteLine("Punkt: " + point.toString());
                    }
                }


                List <Point> pointsResult = candiatesPoints[candiatesPoints.Count - 1];
                Debug.WriteLine("Pierwszy punkt: " + pointsResult[0].toString());
                Debug.WriteLine("Drugi punkt: " + pointsResult[1].toString());
                boundaryPointsForOne.Add(pointsResult[0]);
                boundaryPointsForOne.Add(pointsResult[1]);
                boundaryPoints.Add(boundaryPointsForOne);
            }
        }