static void Main() { CarCollection cars = new CarCollection(); cars.Add(new Car { Make = "Ford", Model = "Mustang" }); cars.Add(new Car { Make = "Honda", Model = "Accord" }); cars.Add(new Car { Make = "Toyota", Model = "Tundra" }); using (MemoryStream memoryStream = new MemoryStream()) { DataContractSerializer serializer = new DataContractSerializer(typeof(CarCollection)); serializer.WriteObject(memoryStream, cars); memoryStream.Position = 0; String xml = null; using (StreamReader reader = new StreamReader(memoryStream)) { xml = reader.ReadToEnd(); reader.Close(); } memoryStream.Close(); } }
static void Main(string[] args) { CarCollection<Car> carCollection = new CarCollection<Car>(); Car miniVan = new Car(); miniVan.Name = "MiniVanCar1"; miniVan.ManufactureDate = DateTime.Parse("01.01.15"); Car miniCar = new Car(); miniCar.Name = "Mini"; miniCar.ManufactureDate = DateTime.Parse("10.10.10"); carCollection.Add(miniVan); carCollection.Add(miniCar); ShowCars(ref carCollection); }
static void Main(string[] args) { IMyList <Car> CC = new CarCollection <Car>(); CC.Add(new Car("Jiguli", DateTime.Now)); CC.Add(new BMW("M5", DateTime.Now)); for (int i = 0; i < CC.Length; i++) { Console.WriteLine(CC[i] + " " + CC[i].GetType()); } Console.ReadKey(); }
/// <summary> /// metoda tworzy nowy obiekt klasy Car i dodaje go do kolekcji CarCollection /// </summary> public void LoadCar() { //utworzenie instancji klasy Car Car car = new Car(); //dodanie instancji klasy Car do Canvasu AddToCanvas(car); //losowanie predkosci dla utworzonego obiektu klasy Car car.CarSpeed = rnd.NextDouble(); //predkosc obiektu klasy Car musi byc co najmniej rowna 0,4 if (car.CarSpeed < 0.4) { car.CarSpeed += 0.4; } //sprawdzenie czy kolekcja zawiera przynajmniej 1 item oraz czy zaden z jej itemow nie posiada juz przypisanej ktoremus obiektowi predkosci if (CarCollection.Any(x => x.CarSpeed == car.CarSpeed) && CarCollection.Count != 0) { while (CarCollection.Any(x => x.CarSpeed == car.CarSpeed)) { //jezeli ktorys obiekt w kolekcji posiada ta sama predkosc co dodawany samochodzik //predkosc nowego samochodziku jest losowana ponownie tak dlugo az bedzie unikalna car.CarSpeed = rnd.NextDouble(); if (car.CarSpeed < 0.4) { car.CarSpeed += 0.4; } } } //dodanie obiektu klasy Car do kolekcji CarCollection.Add(car); //wywolanie metody poruszajacej samochodzik po Canvasie pathBuilder.MoveCarMatrix(car); }
public void addVehicle <T>(T vehicle) { if (typeof(Car).IsInstanceOfType(vehicle)) { CarCollection.Add(vehicle as Car); } else if (typeof(Truck).IsInstanceOfType(vehicle)) { TruckCollection.Add(vehicle as Truck); } }
public void OnNavigatedTo(INavigationParameters parameters) { UnityContainer unity = parameters.GetValue <UnityContainer>("UnityContainer"); _carService = unity.Resolve <CarService>(); DeviceType = "Wat een mooie " + _deviceService.GetDeviceOS() + " telefoon heb jij! :)’"; foreach (Car c in _carService.GetCars()) { CarCollection.Add(c); } }
static void Main(string[] args) { var carCollection = new CarCollection<Car>(); carCollection.Add(new Car("BMW M3", 2000)); carCollection.Add(new Car("Ford Mustang", 1967)); carCollection.Add(new Car("Moskvich 412", 1975)); carCollection.Add(new Car("Porshe 911", 2015)); Console.WriteLine(" CAR COLLECTION"); Console.WriteLine("{0,-15} {1,-4}", "NAME", "MANUFACTURE YEAR"); for (int i = 0; i < carCollection.Count; i++) { Console.WriteLine("{0,-15} {1,-4}", carCollection[i].Name, carCollection[i].ManufactYear); } carCollection.Clear(); Console.WriteLine("\nCollection was cleared. Count = {0}", carCollection.Count); Console.ReadKey(); }
// Methods public void DoCommand(object newItem) { int cmdId = ID; string cmdName = Name; string cmdBrand = Brand; string cmdColor = Color; int cmdYear = Year; string cmdComment = Comment; Car car = _carCatalog.CreatNewCar(cmdId, cmdName, cmdBrand, cmdColor, cmdYear, cmdComment); CarCollection.Add(car); }
public CarCollection Load() { CarCollection carlst = new CarCollection(); carlst.Add(new Car("アルファード", "3000000", CarMakerType.TOYOTA)); carlst.Add(new Car("オデッセイ", "2800000", CarMakerType.HONDA)); carlst.Add(new Car("レガシー", "2870000", CarMakerType.SUBARU)); carlst.Add(new Car("カローラ", "1800000", CarMakerType.TOYOTA)); carlst.Add(new Car("エルグランド", "3200000", CarMakerType.NISSAN)); carlst.Add(new Car("デリカD5", "2500000", CarMakerType.MITSUBISHI)); carlst.Add(new Car("GT-R", "5000000", CarMakerType.NISSAN)); carlst.Add(new Car("ROADSTAR", "2300000", CarMakerType.MAZDA)); return carlst; }
public void Add(Interfaces.ICar item) { CarCollection.Add(item); }