Esempio n. 1
0
        static void Main(string[] args)
        {
            Car car1 = new Car();
            Car car2 = new Car();

            car1.speed = 200;
            car2.speed = 250;
            CollectionType <Car> list = new CollectionType <Car>();

            list.Add(car1);
            list.Add(car2);
            string           path = @"C:\Users\murug\forlab8.txt";
            DoublyNode <Car> temp = list.head;

            try
            {
                using (StreamWriter sw = new StreamWriter(path, false, System.Text.Encoding.Default))
                {
                    while (temp != null)
                    {
                        sw.WriteLine(temp.Data.speed);
                        temp = temp.Next;
                    }
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
            finally
            {
                Console.WriteLine("Запись в файл");
            }
            list.FileRead();
        }
Esempio n. 2
0
        static void Main(string[] args)
        {
            int[] Arrint = new int[5] {
                4, 5, 18, 56, 8
            };
            CollectionType <int> numbers = new CollectionType <int>(Arrint.Length, Arrint);

            for (int j = 0; j < 10; j++)
            {
                numbers.Add(j);
            }
            numbers.Remove(5);
            numbers.Remove(56);
            char[] vs = new char[2] {
                'h', 'A'
            };
            CollectionType <char> collectionType = new CollectionType <char>(vs.Length, vs);

            collectionType.Add('s');
            collectionType.Add('s');
            collectionType.Remove('A');
            //CollectionType<Invent> invent = new CollectionType<Invent>(Arrint.Length);
            for (int i = 0; i < numbers.Count(); i++)
            {
                Console.WriteLine(numbers.GetItem(i));
            }
            Console.WriteLine("===================================");
            for (int i = 0; i < collectionType.Count(); i++)
            {
                Console.WriteLine(collectionType.GetItem(i));
            }
            Console.ReadKey();
        }
Esempio n. 3
0
        //---------------------------------------------------

        public static CollectionType <T> operator *(CollectionType <T> list1, CollectionType <T> list2)//объединение двух списков
        {
            DoublyNode <T>     head1 = list1.head;
            DoublyNode <T>     head2 = list2.head;
            CollectionType <T> list3 = new CollectionType <T>();

            while (head1 != null)
            {
                list3.Add(head1.Data);
                head1 = head1.Next;
            }
            while (head2 != null)
            {
                list3.Add(head2.Data);
                head2 = head2.Next;
            }
            return(list3);
        }
Esempio n. 4
0
        static void Main(string[] args)
        {
            Password password1 = new Password();

            Console.WriteLine("Введите пароль:");
            password1.Parol = Console.ReadLine();

            Password password2 = new Password();

            Console.WriteLine("Введите второй пароль:");
            password2.Parol = Console.ReadLine();

            Password password3 = new Password();

            Console.WriteLine("Введите третий пароль:");
            password3.Parol = Console.ReadLine();

            Password password4 = new Password();

            Console.WriteLine("Введите четвёртый пароль:");
            password4.Parol = Console.ReadLine();

            Console.WriteLine("--------------------------------------------------------");

            CollectionType <Password> myCollection = new CollectionType <Password>();

            myCollection.Add(password1);
            myCollection.Add(password2);
            myCollection.Add(password3);
            myCollection.Add(password4);
            myCollection.Check();

            Console.WriteLine("--------------------------------------------------------");

            bool exept = false;

            try
            {
                Password giveMe = myCollection.Delete(2);
                Console.WriteLine($" Извлечённый пароль {giveMe.Parol}");
                myCollection.Check();
            }

            catch (ArgumentOutOfRangeException ex)
            {
                Console.WriteLine(ex.Message + "\n" + ex.Source);
                exept = true;
            }
            finally
            {
                if (exept)
                {
                    Console.WriteLine("Исключение обработано");
                }
                else
                {
                    Console.WriteLine("Исключение не обработано либо не произошло");
                }
            }

            Console.WriteLine("--------------------------------------------------------");

            bool exept2 = false;

            try
            {
                StandartTypes <int, double, byte> myTypes = new StandartTypes <int, double, byte>(1234, 123.4, 8); // обобщение для проверки типов
                myTypes.ShowTypes();
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message + "\n" + ex.Source);
                exept2 = true;
            }
            finally
            {
                if (exept2)
                {
                    Console.WriteLine("Исключение обработано");
                }
                else
                {
                    Console.WriteLine("Исключение не обработано либо не произошло");
                }
            }

            myCollection.WriteToFile();

            Console.ReadKey();
        }