public Lamborghini GetLamborghini(int id) //id will allow caller of method to pick out a different type of Lambo. { Lamborghini lamborghiniToReturn = null; foreach (var lamborghini in _lamborghini) //Foreach loop will go through all elements in array. The variable you define for the loop (lamborghini) will be set to one of the elements of the array. { //So the first time the loop runs lamborghini, lamborghini will be set to the first item in the private array _lamborghini. Second time it will be set to the second item etc. if (lamborghini.Id == id) //If statement checking if lamborghini item id property equals the id passed into method. { lamborghiniToReturn = lamborghini; //Matches id we're looking for to id inputted. So if 1 is performante and you type in 1 it will check it's matched. break; //<-- breaks out of loop when matching id is found. //If id is matched lamborghiniToReturn wont be null it'll be a value matched in _lamborghini. } } return(lamborghiniToReturn); //<- if loop finishes then means that none of the lamborghini in the items array had an id that matched what was passed into method, so will return null. }
/// <summary> /// Point d'entré du programme. /// </summary> /// <param name="args"></param> static void Main(string[] args) { // Affichage de l'en-tête Console.WriteLine("--------- Test d'utilisation des décorateurs ---------"); Console.WriteLine(); Console.WriteLine(); // Déclaration de la voiture Client0 Voiture client0 = new Lamborghini(); client0 = new ToitOuvrant(client0); client0 = new SystemeMultimedia(client0); client0 = new LotPneu(client0); // Affichage de la voiture Client0 Console.WriteLine("Client 0 :"); Console.WriteLine("\tModele : " + client0.Modele); Console.WriteLine("\tPrix : " + client0.Prix); Console.WriteLine(); // Déclaration de la voiture Client1 Voiture client1 = new Ferrari(); client1 = new Climatisation(client1); // Affichage de la voiture Client1 Console.WriteLine("Client 1 :"); Console.WriteLine("\tModele : " + client1.Modele); Console.WriteLine("\tPrix : " + client1.Prix); Console.WriteLine(); // Ajout d'une option pour le client 1 Console.WriteLine("Le client 1 rappelle pour ajouter une option"); Console.WriteLine(); client1 = new SystemeMultimedia(client1); // Affichage de la voiture Client1 Console.WriteLine("Client 1 :"); Console.WriteLine("\tModele : " + client1.Modele); Console.WriteLine("\tPrix : " + client1.Prix); // Attente de la fermeture du programme Console.ReadKey(); }
static void Main(string[] args) { IFastCarCollection fastCarCollection = new FastCarCollection(); FastCar lamborghini = new Lamborghini(); FastCar bmw = new Bmw(); FastCar benz = new Benz(); fastCarCollection.Attach(lamborghini); fastCarCollection.Attach(bmw); fastCarCollection.Attach(benz); ICarCostomer normalCostomer = new NormalCostomer(); ICarCostomer vipCostomer = new VipCostomer(); fastCarCollection.Accept(normalCostomer); //fastCarCollection.Detach(bmw); fastCarCollection.Accept(vipCostomer); }
public void CreateFactory(Constants.CarEnum carName) { ICar car; if (carName.Equals(Constants.CarEnum.Hyundai)) { car = new Hyundai(); car.ShowDetail(); } else if (carName.Equals(Constants.CarEnum.Lamborghini)) { car = new Lamborghini(); car.ShowDetail(); } else if (carName.Equals(Constants.CarEnum.Mercedes)) { car = new Mercedes(); car.ShowDetail(); } else { Console.WriteLine("This type of car is not exist"); } }
public Car createCar() { this._car = new Lamborghini(); return(this._car); }