Ejemplo n.º 1
0
    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();
        }
    }
Ejemplo n.º 2
0
 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);
 }
Ejemplo n.º 3
0
        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();
        }
Ejemplo n.º 4
0
        /// <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);
        }
Ejemplo n.º 5
0
 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);
     }
 }
Ejemplo n.º 6
0
        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);
            }
        }
Ejemplo n.º 7
0
        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();
        }
Ejemplo n.º 8
0
        // 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);
        }
Ejemplo n.º 9
0
        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;
        }
Ejemplo n.º 10
0
 public void Add(Interfaces.ICar item)
 {
     CarCollection.Add(item);
 }