Example #1
0
        static void Main(string[] args)
        {
            Console.WriteLine("Способ ввода данных : (1 - файл, 2 - ручной ввод)");
            string tmp = "";

            tmp = Console.ReadLine();
            if ((tmp != "1") && (tmp != "2"))
            {
                Console.WriteLine("Неверный способ ввода.");
                return;
            }
            int[,] r = new int[0, 0];
            if (tmp == "2")
            {
                try
                {
                    r = ConsoleMatrix.Input();
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.Message);
                }
            }
            if (tmp == "1")
            {
                Console.WriteLine("Введите имя загружаемого файла :");
                try
                {
                    r = MatrixUtils.FileToMatrix(Console.ReadLine());
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.Message);
                }
            }
            MatrixTools mt = new MatrixTools(r);

            Console.WriteLine("Результат работы : ---------------");
            try
            {
                Console.WriteLine(MatrixUtils.MatrixToStr(mt.GetNeighboursMatrix()));
                Console.WriteLine("Сохранить введенную матрицу ? (1 - да, 2 - нет) :");
                tmp = Console.ReadLine();
                if ((tmp != "1") && (tmp != "2"))
                {
                    Console.WriteLine("Неверный ответ.");
                }
                if (tmp == "1")
                {
                    MatrixUtils.MatrixToFile(r, Console.ReadLine());
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
        }
Example #2
0
        private void buttonRun_Click(object sender, EventArgs e)
        {
            int[,] r;
            MatrixTools work = new MatrixTools(SourceGridMatrix.GetMatrix());

            try
            {
                r = work.GetNeighboursMatrix();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                return;
            }
            ResultGridMatrix.SetMatrix(r);
        }