Exemplo n.º 1
0
        public static void Main(string[] args)
        {
            Message  mes, mes2, mes3;
            Republic ukraine = new Republic();
            Monarchy spain   = new Monarchy("Spain", 70000000);
            Kingdom  uk      = new Kingdom("United Kingdom", 140000000);

            ukraine.Name       = "Ukraine";
            ukraine.Population = 41000000;

            mes = ukraine.Info;

            mes2  = spain.Info;
            mes2 += uk.Info;
            mes3  = mes + mes2;
            mes3();

            Console.WriteLine();

            IDerzhava[] masiv = new IDerzhava[3];

            masiv[0] = ukraine;
            masiv[1] = spain;
            masiv[2] = uk;

            foreach (IDerzhava derzh in masiv)
            {
                mes += derzh.Info;
            }

            mes.Invoke();
        }
Exemplo n.º 2
0
        public static void Main(string[] args)
        {
            Republic ukraine = new Republic();
            Monarchy spain   = new Monarchy("Spain", 70000000);
            Kingdom  uk      = new Kingdom("United Kingdom", 140000000);

            ukraine.Name       = "Ukraine";
            ukraine.Population = 41000000;

            ukraine.Info();
            spain.Info();
            uk.Info();

            Console.WriteLine();

            IDerzhava[] masiv = new IDerzhava[3];

            masiv[0] = ukraine;
            masiv[1] = spain;
            masiv[2] = uk;

            foreach (IDerzhava derzh in masiv)
            {
                derzh.Info();
            }
        }
Exemplo n.º 3
0
        public async Task <IActionResult> Edit(string id, [Bind("Title,Population,Square")] Republic republic)
        {
            if (id != republic.Title)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(republic);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!RepublicExists(republic.Title))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(republic));
        }
Exemplo n.º 4
0
        public async Task <IActionResult> Create([Bind("Title,Population,Square")] Republic republic)
        {
            if (ModelState.IsValid)
            {
                _context.Add(republic);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(republic));
        }
Exemplo n.º 5
0
        public async Task <Unit> Handle(AddRepublicViewModel request, CancellationToken cancellationToken)
        {
            var Republic = new Republic()
            {
                Title      = request.Title,
                Population = request.Population,
                Square     = request.Square
            };

            if (Republic != null)
            {
                await covidDbContext.Republics.AddAsync(Republic);

                await covidDbContext.SaveChanges(cancellationToken);
            }
            return(Unit.Value);
        }
Exemplo n.º 6
0
        static void Main(string[] args)
        {
            // Republic class.
            Republic republic = new Republic("The Republic of the Congo", "Denis Sassou Nguesso", 5125821, 58, "Africa", 7, 72, 6);

            // Monarchy class.
            Monarchy monarchy = new Monarchy("Belgium", "Philippe", 11358357, 189, "Europe", "The House of Saxe-Coburg and Gotha");

            // Kingdom class.
            Kingdom kingdom = new Kingdom("The Kingdom of Saudi Arabia", "Salman", 33000000, 87, "Asia", "The Sudairi Seven");

            // Array of objects of classes that use IComparable interface
            IComparable[] comparable = new IComparable[3];
            comparable[0] = republic;
            comparable[1] = monarchy;
            comparable[2] = kingdom;

            // Recreation of the array but with the AbstrState class
            AbstrState[] abstrState = new AbstrState[3];
            for (int i = 0; i < comparable.Length; i++)
            {
                abstrState[i] = (AbstrState)comparable[i];
            }

            Console.WriteLine("THE RESULT OF THE 3RD TASK:");
            // Showing the array
            Console.WriteLine("CREATED ARRAY:");
            foreach (AbstrState a in abstrState)
            {
                a.Show();
            }

            // Sorting the array
            Array.Sort(abstrState, new ComparePopulation());

            // Showing the sorted array
            Console.WriteLine("ARRAY AFTER BEING SORTED BY POPULATION:");
            foreach (AbstrState a in abstrState)
            {
                a.Show();
            }

            Array.Sort(abstrState, new CompareName());
            Console.WriteLine("ARRAY AFTER BEING SORTED BY NAME:");
            foreach (AbstrState a in abstrState)
            {
                a.Show();
            }

            Array.Sort(abstrState, new CompareLeaderName());
            Console.WriteLine("ARRAY AFTER BEING SORTED BY LEADER NAME:");
            foreach (AbstrState a in abstrState)
            {
                a.Show();
            }

            Array.Sort(abstrState, new CompareAge());
            Console.WriteLine("ARRAY AFTER BEING SORTED BY AGE:");
            foreach (AbstrState a in abstrState)
            {
                a.Show();
            }

            Array.Sort(abstrState, new CompareContinent());
            Console.WriteLine("ARRAY AFTER BEING SORTED BY CONTINENT:");
            foreach (AbstrState a in abstrState)
            {
                a.Show();
            }

            // Binary search demonstration
            DemostrateBinarySearch(abstrState);


            // Shallow clone
            Republic shallowClone = republic.ShallowCopy();
            // Real clone
            Republic clone = (Republic)republic.Clone();

            Console.WriteLine("Shallow clone of the Republic object:");
            shallowClone.Show();
            Console.WriteLine("Clone of the Republic object:");
            clone.Show();

            Console.WriteLine("Press ENTER to exit");
            Console.ReadLine();
        }
Exemplo n.º 7
0
        static void Main(string[] args)
        {
            var countryList = new List <Country>(0);

            WriteLine("Формирование массива");

            var m = new Monarchy("1", 1110, "Россия", "Путин");

            countryList.Add(m);
            WriteLine("\nСоздал: {0}", m);

            var m1 = (Monarchy)m.Clone();

            countryList.Add(m1);
            WriteLine("Скопировал: {0}", m1);
            WriteLine();


            WriteLine("\nИзменяю {0}", m1);
            m1.Population = 9000;
            m1.Name       = "Украина";
            m1.Ruler      = "Порошенко";
            WriteLine("\nИзменил (напрямую): {0}", m1);

            var m2 = new Kingdom("1", 890, "Люксембург", "Король Люксембурга");

            countryList.Add(m2);
            WriteLine("\nСоздал: {0}", m2);

            WriteLine();
            foreach (Country c in countryList)
            {
                WriteLine("   {0}", c);
            }
            WriteLine();

            var uk = new Kingdom("2", 55555, "Соединённое королевство", "Елизавета 2");

            WriteLine("\nСоздал: {0}", uk);
            countryList.Add(uk);
            WriteLine();

            var new_uk = (Kingdom)uk.Clone();

            WriteLine("\nСкопировал: {0}", new_uk);
            countryList.Add(new_uk);

            countryList[4].Ruler      = "Чарльз???";
            countryList[4].Population = 44445;
            WriteLine("\nИзменил (виртуальные методы): {0}", new_uk);

            WriteLine();

            WriteLine();
            foreach (Country c in countryList)
            {
                WriteLine("   {0}", c);
            }
            WriteLine();

            var america = new Republic
                              ("3", 12345, "америка", "Трамп", new [] { "номер 1", "номер 2", "номер 3" });

            countryList.Add(america);
            WriteLine("\nСоздал: {0}", america);

            var brazil = new Monarchy
                             ("3", 11111, "Бразилия", "Президент");

            countryList.Add(brazil);
            WriteLine("\nСоздал: {0}", brazil);


            WriteLine();
            foreach (Country c in countryList)
            {
                WriteLine("   {0}", c);
            }
            WriteLine();


            WriteLine();
            WriteLine("На континенте 1 ровно {0} людей", ContinentPeople(countryList, "1"));
            WriteLine("На континенте 2 ровно {0} людей", ContinentPeople(countryList, "2"));
            WriteLine("На континенте 3 ровно {0} людей", ContinentPeople(countryList, "3"));
            WriteLine();

            WriteLine("Монархи континента 1");
            foreach (string s in ContinentMonarchs(countryList, "1"))
            {
                WriteLine(s);
            }
            WriteLine();

            WriteLine("Монархи континента 2");
            foreach (string s in ContinentMonarchs(countryList, "2"))
            {
                WriteLine(s);
            }
            WriteLine();

            WriteLine("Монархи континента 3");
            foreach (string s in ContinentMonarchs(countryList, "3"))
            {
                WriteLine(s);
            }
            WriteLine();

            WriteLine("Страны кортинента 1");
            foreach (string s in ContinentCountry(countryList, "1"))
            {
                WriteLine(s);
            }
            WriteLine();


            var countryArray = countryList.ToArray();

            Array.Sort(countryArray, new Countries_Lab11.SortByName());
            countryList = countryArray.ToList();


            WriteLine();
            foreach (Country c in countryList)
            {
                WriteLine("   {0}", c);
            }
            WriteLine();

            ReadKey(true);
        }