Exemplo n.º 1
0
        private static async Task Main(string[] args)
        {
            Func <int, int, bool> fa = Compare.Invoke;
            myTimer t = new myTimer();
            await Scrape.Download();

            WriteLine(1__2333_4_5);
            WriteLine(6.023E23F);
            WriteLine(float.MaxValue);
            WriteLine(double.MaxValue);
            WriteLine(decimal.MaxValue);
            WriteLine(0x_2002a);
            WriteLine(0b_00101010101);
            WriteLine($"0x{42:x8}");
            WriteLine(Convert.ToString(42, 2));
            WriteLine();
            const double num = 1.618033988749895;
            double       res;
            string       text;

            text = $"{num}";
            res  = double.Parse(text);
            WriteLine($"{res == num}");

            text = $"{num:R}";
            res  = double.Parse(text);
            WriteLine($"{res == num}");
            WriteLine($"{num:R}\t{res}");
            WriteLine(string.Compare("SBAA", "sbab", StringComparison.OrdinalIgnoreCase));
            Write('\u003a');
            WriteLine('\u0029');
            WriteLine($@"begin
                            /\
                           /  \{text}
                          /    \
                         /______\
end
");
            var price = 9899.66;

            WriteLine($"{{{price,20:C2} }}");

            unchecked
            {
                var maxInt = int.MaxValue;
                WriteLine(++maxInt);
            }

            var(country, capital, gdp) = ("Malawi", "Lilongwe", 226.50);
            var countryInfo = (country, capital, gdp);
            var cInfo       = ("Malawi", Capital : "Lilongwe", 226.50);

            WriteLine($"{countryInfo.country}  {cInfo.Item2}  {gdp}");

            var c     = new[] { new[] { 1, 2, 3 }, new[] { 1, 4, 5, 9 } };
            var cells = new[, ] {
                { 1, 2, 3 }, { 1, 4, 9 }
            };

            c[1][0] = 2;
            var d = c.Clone();

            //Array.Resize(ref cells, 9);
            WriteLine(cells.GetLength(0));
            WriteLine(cells.Rank);

            WriteLine(new string(text.Reverse().ToArray()));
            char[] charArray = text.ToCharArray();
            Array.Reverse(charArray);
            string news = new string(charArray);

            var n = '3' + '5';

            WriteLine((char)n);
            float f = -6f;

            WriteLine(f / 0);
            WriteLine(3.4e38f * 2f);

            if (n > 1 || n < 5)
            {
                WriteLine("ok");
            }

            var x1 = -7;

            x1 >>= 2;
            WriteLine(x1);

            byte and = 12, or = 12, xor = 12;

            and &= 7;
            or  |= 7;
            xor ^= 7;
            WriteLine($"{and}\t{or}\t{xor}");

            WriteLine(Convert.ToString(9989, 2));

            int a = ~-1;

            goto myLabel;
            a++;
            myLabel : WriteLine(Convert.ToString(a, 2));

            var am = new Cat(20)
            {
                StarPoint = 100
            };

            TestReference(am);
            WriteLine($"SP after test: {am.StarPoint}");
            var am2 = new Cat(150, 99)
            {
                StarPoint = 100
            };

            var(age, _, starPoint, _) = am2;
            var(j, k, l) = (3, "", '2');
            am2.Deconstruct(out var age2, out _, out var sp, out _);
            WriteLine($"am2 SP={am2.StarPoint}  age={Cat.Age}");
            WriteLine($"am2 SP={starPoint}  age={age}");

            am.Eat();
            Animal.Sleep();
            am.Run();

            WriteLine($"Sp={am.StarPoint}");
            WriteLine(am.Num);
            WriteLine(Animal.Age);
            WriteLine("---------------------------------");
            Cat ct = (Cat)am;

            WriteLine(ct.Num);
            WriteLine(Cat.Age);
            WriteLine(ct.Name);
            ct.Eat();
            Cat.Sleep();
            ct.Run();
            ct.CatchMouse();
            var an = new Animal();

            WriteLine(an.Num);
            var sortArr = new[] { 1, 8, 2, 0, -3, 12, 6 };

            Array.Sort(sortArr);
            Array.Resize(ref sortArr, 10);
            WriteLine(sortArr.Length);
            int?a1 = sortArr?[1];

            foreach (var i in sortArr)
            {
                Write(i + " ");
            }
            WriteLine();
            var o = new object();

            if (o is string str && str.Length > 2)
            {
                int.TryParse(str, out _);
            }
Exemplo n.º 2
0
        static void Main(string[] args)
        {
            float  weight;
            float  height;
            int    normalAmountOfFood;
            string input;
            int    number;
            string numberPet;
            string coatColor = "Черный";
            string eyesColor = "Зеленый";

            do
            {
                Console.WriteLine("Введите вес вашего питомца: ");
                input = Console.ReadLine();
                Console.Clear();
            } while (!float.TryParse(input, out weight));
            do
            {
                Console.WriteLine("Введите рост вашего питомца: ");
                input = Console.ReadLine();
                Console.Clear();
            } while (!float.TryParse(input, out height));
            do
            {
                Console.Clear();
                Console.WriteLine("Введите количество потребляемой пищи вашего питомца ежедневно: ");
                input = Console.ReadLine();
                Console.Clear();
            } while (!int.TryParse(input, out normalAmountOfFood));
            Pet pet = new Cat(weight, height, normalAmountOfFood, coatColor);

            do
            {
                Console.Clear();
                Console.WriteLine("Выберите животное:\n" +
                                  "1. Кот\n" +
                                  "2. Собака\n");
                numberPet = Console.ReadLine();
            } while (numberPet != "1" && numberPet != "2");
            if (numberPet == "1")
            {
                pet = new Cat(weight, height, normalAmountOfFood, coatColor);
            }
            else if (numberPet == "2")
            {
                pet = new Dog(weight, height, normalAmountOfFood, eyesColor);
            }
            while (true)
            {
                do
                {
                    Console.WriteLine("Выберите действие:\n" +
                                      "1. Вывести информацию\n" +
                                      "2. Показать состояние\n" +
                                      "3. Покормить\n" +
                                      "4. Охотиться\n" +
                                      "5. Погладить\n" +
                                      "6. Уложить спать");
                    input = Console.ReadLine();
                } while (!int.TryParse(input, out number) && (number < 1 || number > 6));
                Console.Clear();
                switch (number)
                {
                case 1:
                    pet.ShowInformation();
                    break;

                case 2:
                    pet.StateInformation();
                    break;

                case 3:
                    pet.Feel();
                    break;

                case 4:
                    pet.Hunt();
                    break;

                case 5:
                    pet.Caress();
                    break;

                case 6:
                    pet.Drowsiness();
                    break;
                }
            }
        }
Exemplo n.º 3
0
        static void Main(string[] args)
        {
            float  weight;
            float  height;
            int    normalAmountOfFood;
            string name;
            string input;
            int    number;
            string numberPet;
            string coatColor = "Черный";
            string eyesColor = "Зеленый";

            Console.WriteLine("Введите имя: ");
            name = Console.ReadLine();
            do
            {
                Console.WriteLine("Введите вес вашего питомца: ");
                input = Console.ReadLine();
                Console.Clear();
            } while (!float.TryParse(input, out weight));
            do
            {
                Console.WriteLine("Введите рост вашего питомца: ");
                input = Console.ReadLine();
                Console.Clear();
            } while (!float.TryParse(input, out height));
            do
            {
                Console.Clear();
                Console.WriteLine("Введите количество потребляемой пищи вашего питомца ежедневно: ");
                input = Console.ReadLine();
                Console.Clear();
            } while (!int.TryParse(input, out normalAmountOfFood));
            Pet pet = new Pet(name, weight, height, normalAmountOfFood);

            do
            {
                Console.Clear();
                Console.WriteLine("Выберите животное:\n" +
                                  "1. Кот\n" +
                                  "2. Собака\n");
                numberPet = Console.ReadLine();
            } while (numberPet != "1" && numberPet != "2");
            if (numberPet == "1")
            {
                pet = new Cat(name, weight, height, normalAmountOfFood, coatColor);
            }
            else if (numberPet == "2")
            {
                pet = new Dog(name, weight, height, normalAmountOfFood, eyesColor);
            }
            while (true)
            {
                do
                {
                    Console.WriteLine("Выберите действие:\n" +
                                      "1. Вывести информацию\n" +
                                      "2. Показать состояние\n" +
                                      "3. Покормить\n" +
                                      "4. Охотиться\n" +
                                      "5. Погладить\n" +
                                      "6. Уложить спать\n" +
                                      "7. Сравнить животных");
                    input = Console.ReadLine();
                } while (!int.TryParse(input, out number) && (number < 1 || number > 7));
                Console.Clear();
                switch (number)
                {
                case 1:
                    pet.ShowInformation();
                    break;

                case 2:
                    pet.StateInformation();
                    break;

                case 3:
                    pet.Feel();
                    break;

                case 4:
                    pet.Hunt();
                    break;

                case 5:
                    pet.Caress();
                    break;

                case 6:
                    pet.Drowsiness();
                    break;

                case 7:
                    List <BodyData> dic = new List <BodyData>();
                    dic.Add(new BodyData(name, weight, height, normalAmountOfFood));
                    dic.Add(new BodyData("Барсик", 9, 10, 1));
                    dic.Add(new BodyData("Мурзик", 8, 12, 2));
                    dic.Add(new BodyData("Дымка", 11, 9, 1));
                    dic.Add(new BodyData("Багира", 10, 8, 1));
                    dic.Add(new BodyData("Алиса", 7, 13, 1));
                    Console.WriteLine("Животные: ");
                    foreach (BodyData i in dic)
                    {
                        Console.WriteLine(i);
                    }
                    Console.WriteLine("Отсортированные по весу: ");
                    dic.Sort();
                    foreach (BodyData i in dic)
                    {
                        Console.WriteLine(i);
                    }
                    break;
                }
            }
        }