public string ShowVehicleListType(Garage <Vehicle> garage) { string result = ""; var vehlist = garage.OfType <Vehicle>().Where(x => x != null).GroupBy(x => x.GetType().Name).Select(gar => new { type = gar.Key, count = gar.Count() }); foreach (var veh in vehlist) { result += veh.type + ": " + veh.count + "\n"; } return(result); }
public void FindVehicleByType(Garage <Vehicle> garage, string type) { var vehlist = garage.OfType <Vehicle>().Where(v => v.GetType().Name.Equals(type, StringComparison.InvariantCultureIgnoreCase)); if (vehlist.Count() == 0) { Console.WriteLine("The type {0} was not found", type); } else { foreach (var veh in vehlist) { Console.WriteLine(veh); } } }
public void FindVehicleByColor(Garage <Vehicle> garage, string color) { var vehlist = garage.OfType <Vehicle>().Select((v, i) => new { vehicle = v, Index = i }).Where(x => x.vehicle != null && x.vehicle.Color == color).ToDictionary(x => x.Index, x => x.vehicle); if (vehlist.Count == 0) { Console.WriteLine("Not find any vehicle with {0} color ", color); } else { foreach (var veh in vehlist) { Console.WriteLine("Parking place: " + (veh.Key + 1) + "\n" + veh.Value); } } }
public void FindVehicleByWheels(Garage <Vehicle> garage, int numberOfWheels) { var vehlist = garage.OfType <Vehicle>().Select((veh, i) => new { vehicle = veh, Index = i }).Where(x => x.vehicle != null && x.vehicle.NumberOfWheels == numberOfWheels).ToDictionary(x => x.Index, x => x.vehicle); if (vehlist.Count == 0) { Console.WriteLine("Not find any vehicle with {0} wheels ", numberOfWheels); } else { foreach (var veh in vehlist) { Console.WriteLine("Parking Place: " + (veh.Key + 1) + "\n" + veh.Value); } } }
public void FindVehicleByRegistrationNumber(Garage <Vehicle> garage, string regNr) { var vehlist = garage.OfType <Vehicle>().Select((veh, i) => new { vehicle = veh, Index = i }).Where(x => x.vehicle != null && x.vehicle.RegistrationNumber.Contains(regNr)).ToDictionary(x => x.Index, x => x.vehicle); if (vehlist.Count == 0) { Console.WriteLine("The vehicle with registration number {0} is not found", regNr); } else { foreach (var veh in vehlist) { Console.WriteLine("Parking place: " + (veh.Key + 1) + "\n" + veh.Value); } } }